Yes that is working as intended, you have B and C together in their own task, and A can't be in it because it is single instance.
Again, just ignore single instance unless you have a clear reason for using it, and then you will want to structure the rest of your interaction to work well with it. At this point I would suggest focusing questions on what you are actually trying to accomplish. On Tue, Jun 22, 2010 at 1:31 AM, Vibhor Mahajan <[email protected]>wrote: > Hello, > > Thanks Dianne for reply. I understood your point. But after doing some more > tests I have confusions. Kindly provide some suggestions. > > Activity A has SINGLEINSTANCE and B & C has STANDARD launch mode. > Execute below steps: > 1. Start A from launcher > 2. Launch B from A. (oncreate of B is called) > 3. Launch A from B. (re-starts A because A has SINGLEINSTANCE launchmode) > 4. Launch C from A. (oncreate of C is called) > 5. Launch A from C. (re-starts A because A has SINGLEINSTANCE launchmode) > 6. Launch B from A again. > > From step 6 above, instance of B is NOT CREATED instead task containing > activity B & C comes in foreground, with last state of C (from step4) > displayed. (because C was on top of this task). > > Similar behavior is documented in > http://developer.android.com/guide/topics/fundamentals.html link. "If it > does, it is not in position to handle the intent, and the intent is dropped. > (Even though the intent is dropped, its arrival would have caused the task > to come to the foreground, where it would remain.)" > > Q1) Why new instance of B is not created even though B has standard launch > mode and also not top of destination task? > > Now if I change the implementation as below: > Activity A has STANDARD and B has SINGLEINSTANCE launch mode. > Repeat same steps again: > 1. Start A from launcher > 2. Launch B from A. (oncreate of B is called) > 3. Launch A from B. (a new instance of A is created, in the same task in > which A's instance was created in step 1. Now stack is A - A) > 4. Launch B from A re-starts B. > 5. Launch A from B. (a new instance of A is created, in the same task in > which A's instance was created in step 1. Now stack is A - A - A) > > Executing step 4 & 5 repeatedly, creates multiple instances of A. > > Q2) Step 3 & 5, B creates an intent to start A with FLAG_ACTIVITY_NEW_TASK. > Why new instance of A is created in same task in which A was launched from > launcher? > Q3) Shouldn't the behavior be same as explained in previous message i.e. A > should be brought to foreground? > > Thanks, > Vibhor > > On Tue, Jun 22, 2010 at 10:41 AM, Dianne Hackborn <[email protected]>wrote: > >> 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 <[email protected] >> > 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 <[email protected]>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 <[email protected]> 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 >>>> [email protected] >>>> To unsubscribe from this group, send email to >>>> [email protected]<android-developers%[email protected]> >>>> 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 [email protected] >>> To unsubscribe from this group, send email to >>> [email protected]<android-developers%[email protected]> >>> For more options, visit this group at >>> http://groups.google.com/group/android-developers?hl=en >>> >> >> >> >> -- >> Dianne Hackborn >> Android framework engineer >> [email protected] >> >> 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 [email protected] >> To unsubscribe from this group, send email to >> [email protected]<android-developers%[email protected]> >> 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 [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

