Thursday, January 5, 2012

[android-developers] Re: Android activity/task order issue

I played around with some more settings, and it seems that setting the
android:taskAffinity field in the activity manifest fixes this. It
seems that although FLAG_ACTIVITY_NEW_TASK and singleTask is supposed
to start the activity in a new task, for some reason it doesn't.
Manually setting the taskAffinity to some random string seems to work.
Still wondering why the flags don't work as advertised though...

On Jan 6, 10:25 am, galapogos <gois...@gmail.com> wrote:
> Hi,
>
> I've also noticed that launching activity 2 with
> FLAG_ACTIVITY_NEW_TASK does not seem to work. Everytime activity 2 is
> launched again, a new instance of activity 2 is created - I've
> verified this with hierachy viewer. According to documentation:
>
> "Start the activity in a new task. If a task is already running for
> the activity you are now starting, that task is brought to the
> foreground with its last state restored and the activity receives the
> new intent in onNewIntent().
>
> This produces the same behavior as the "singleTask" launchMode value,
> discussed in the previous section."
>
> Hence, a new instance should not be created.
>
> However, if I specify android:launchMode="singleTask" in activity2's
> manifest, then the same instance is just switched to rather than
> creating a new one, which is the behavior that I want and the behavior
> indicated in the documentation.
>
> Does anyone know why this is so? android:launchMode="singleTask" and
> FLAG_ACTIVITY_NEW_TASK should produce the same behavior.
>
> On Jan 5, 12:56 pm,galapogos<gois...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I have an app with 2 main activities and a service. The app starts
> > with activity 1, and the service launches activity 2 via an intent
> > upon detection of an app launch A. Activity 2 then does some stuff and
> > calls finish(), returning to app A.
>
> > However, if I launch app A when I'm in activity 1, activity 2 appears
> > and returns to activity 1 once it's done instead of returning to app
> > A. If I then tap on the back button, I return to app A.
>
> > On the other hand, if I go back to the home screen when I'm on
> > activity 1 and start app A, activity 2 appears, and now returns to app
> > A once it's done. This is the behavior I'm looking for, but it only
> > happens when I'm not starting out from activity 1.
>
> > Why does this happen? I'm launching activity 2 via an intent in the
> > service with the FLAG_ACTIVITY_NEW_TASK flag.
>
> > Thanks.

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate