First, you almost certainly don't want to use singleInstance.  It is for
very special situations, and has significant repercussions on UI flow that
you need to understand before touching it.

The key point about this is this statement in "Launch modes"
http://developer.android.com/guide/topics/fundamentals.html#lmodes

<http://developer.android.com/guide/topics/fundamentals.html#lmodes>*Whether
the instance can have other activities in its task*. A "singleInstance"
activity stands alone as the only activity in its task. If it starts another
activity, that activity will be launched into a different task regardless of
its launch mode — as if FLAG_ACTIVITY_NEW_TASK was in the intent. In all
other respects, the "singleInstance" mode is identical to "singleTask".

This means that when you launch B, it is the root of its own new task.  When
you launch B again, the task for it already exists, then the current task
will be brought to the foreground instead of starting a new instance.  You
have effectively turned yourself into a launcher, so get the behavior
expected for a launcher.

On Mon, Jun 21, 2010 at 9:45 PM, Vibhor Mahajan <mahajan.vib...@gmail.com>wrote:

> Hello,
>
> As per the documentation, standard and singletop differ in just one way,
> standard activity instance is created every time but singletop instance may
> or may not be created. I verified this, if in the above code, reverse
> launchmode of activity A & B i.e. Now A has STANDARD and B as
> SINGLEINSTANCE.
>
> Repeat same steps again:
> 1. Click button in Activity A starts B. (oncreate of B is called)
> 2. Click button in Activity B creates a new instance A. (oncreate of A is
> called, because A now has STANDARD launchmode)
> 3. Click button in Activity A re-starts B. (oncreate of B is NOT CALLED,
> because B now has SINGLEINSTANCE launchmode)
>
> This is exactly as per the documentation.
>
> Kindly help in understanding why in original source code, multiple
> instances of B is not created, though B is having STANDARD launch mode?
>
> Thanks,
> Vibhor
>
>
> On Mon, Jun 21, 2010 at 8:15 PM, MobDev <developm...@mobilaria.com> wrote:
>
>> Btw, got this from documentation, concentrate on the last sentence :
>> "Every time there's new intent for a "standard" activity, a new
>> instance of the class is created to respond to that intent. Each
>> instance handles a single intent. Similarly, a new instance of a
>> "singleTop" activity may also be created to handle a new intent.
>> However, if the target task already has an existing instance of the
>> activity at the top of its stack, that instance will receive the new
>> intent (in an onNewIntent()  call); a new instance is not created."
>> found here :
>>
>> http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
>>
>> On 21 jun, 13:30, Vibhor Mahajan <mahajan.vib...@gmail.com> wrote:
>> > Hello,
>> >
>> > What is launch mode of an activity, which is launched from an activity
>> > with launch mode as "singleinstance". I tried the following code.
>> >
>> > My application has two activities i.e. A & B. Activity A has
>> > "singleinstance" launchmode set and activity B has "standard" launch
>> > mode set. Android manifest file is as follows:
>> >
>> > <application android:icon="@drawable/icon" android:label="@string/
>> > app_name" >
>> >         <activity android:name=".activity_lifecycle"
>> >                   android:label="@string/app_name"
>> >                   android:launchMode="singleInstance">
>> >             <intent-filter> <action
>> > android:name="android.intent.action.MAIN" />
>> >                 <category
>> > android:name="android.intent.category.LAUNCHER" />
>> >             </intent-filter>
>> >         </activity>
>> >         <activity android:name=".another"
>> > android:launchMode="standard" ></activity>
>> >     </application>
>> >
>> > Activity A has a button, clicking button starts Activity B using below
>> > code:
>> > public void onClick(View v) {
>> >         // TODO Auto-generated method stub
>> >         Intent intent = new
>> > Intent(activity_lifecycle.this,another.class);
>> >         startActivityForResult(intent, 0);
>> >
>> > }
>> >
>> > Activity B has a button, clicking button starts Activity A using below
>> > code:
>> > public void onClick(View v) {
>> >         // TODO Auto-generated method stub
>> >         Intent intent = new
>> > Intent(another.this,activity_lifecycle.class);
>> >         startActivityForResult(intent, 0);
>> >
>> > }
>> >
>> > Click button in Activity A starts B. (oncreate of B is called)
>> > Click button in Activity B re-starts A. (because A has SINGLEINSTANCE
>> > launchmode)
>> > Click button in Activity A re-starts B. (oncreate of B is NOT CALLED)
>> >
>> > After 3rd step, since activity B is standard, a new instance should be
>> > created and not previous instance to be used.
>> >
>> > Kindly suggest why when second time activity B is started, a new
>> > instance of activity B is not created, when it is declared with
>> > launchmode "standard".
>> >
>> > Regards,
>> > Vibhor
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to