Let's say for the purposes of my specialized Application, I would like
to have two Tasks (thus back stacks) that can be run by the user
within an Application.

Task A (with task affinity "A") --> Activity A1, Activity A2, Activity
A3
Task B (with task affinity "B") --> Activity B1, Activity B2, Activity
B3

Assume that Activity A1 is the MAIN/LAUNCHER Activity, such that Task
A, Activity A1 becomes the main Application Task.  Assume I have a
menu that allows switching between the tasks.

1. If the App starts in Activity A1 (Task A), as it should, and I want
to switch to Task B, is it correct that the menu which does the switch
should call:

    startActivity(new Intent(context, ActivityA1.class)  (with
FLAG_ACTIVITY_NEW_TASK) ?

2. Likewise, to switch to Task B, I assume the similar menu call
should be:

    startActivity(new Intent(context, ActivityB1.class) (with
FLAG_ACTIVITY_NEW_TASK) ?

3. If I have previously navigated to Activity B3 in Task B, such that
Task B's stack is B1, B2, B3, and I'm back in Task A at the moment,
when I want to switch back to Task B and arrive at the current
activity B3, then using the menu, I assume I would still use:

    startActivity(new Intent(context, ActivityB1.class) (with
FLAG_ACTIVITY_NEW_TASK)

This seems to work empirically, HOWEVER, I don't understand "why" this
works, after I have already navigated around in Task B?  I understand
why it would work the first time, to start Task B, but I don't
understand why on subsequent calls, when I perform startActivity, Task
B is resume dat the last Activity (B3) it left off from, rather than
add a new Activity (B1) to Task B's stack, such that the stack is B1,
B2, B3, B1.  While I WANT it to resume Task B where it left off, I
don't understand why Task B doesn't have an extra Activity B1 added to
the end after I startActivity on subsequent starts?  None of the
Activities are defined as 'singleTop', or 'clearTop', or whatever.
They are standard Activities in the manifest.

4. Following up on point 3, what if I DO want to switch to Task B, and
add a new Activity B1 to the end of the stack?  What call would I make
(from the menu action code) to do this?

5. I don't understand how the LAUNCHER does this either, that is,
resume a Task at the last place it left off, rather than add a new
Activity (root Activity) to the end of the Task's back stack?  I
assume the LAUNCHER is doing the same thing I'm doing in the menu
action call?

6. If the user hits the HOME button while in Task B (NOT the main
application Task), and then they re-enter the App via the launcher
(for Activity A1, Task A), how can I cause the App to enter back where
I left off in Task B?  The LAUNCHER doesn't know about Task B, but
there must be a way?  Do I need to override onCreate() in Activity A1,
look up the last active task/activity name I stored in
SharedPreferences, and then startActivity on that Activity in
onCreate(), then call finish() on A1 (which the LAUNCHER just
launched)?

7. If I want two separate Tasks in my app, do I actually need to
define the Activities to have explicit taskAffinity in the manifest
(i.e. Activity A1,A2,A3 with affinity "A", and B1, B2, B3 with
affinity "B")?  Or can I allow Activity A1, A2, A3 to inherit the main/
default application Task affinity, and then just start Task B from my
menu using FLAG_ACTIVITY_NEW_TASK, whereby Android will assign a new
globally unique Task affinity to Activity B1, B2, B3 in Task B?


I hope my questions makes sense, and I'm not thinking about this
wrong.  If I am, I would appreciate it if someone would describe the
proper way to have multiple Tasks within an Application, and the
proper way to jump around to each Task.  Or, possibly suggest another
Paradigm that will achieve the same goal without the use of multiple
Tasks?




-- 
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

Reply via email to