0

I have the following constellation:

Press App Icon open Activity A, which checks which activity should open next (Registration or Main Activity B). A is marked as Main Launcher in the xml. Now I go to B. Then I have a user action and come to Activity C. Now I press home. If I chose the app again from background task selector i come back to C. But when I instead press the app icon again,I will start again with A. Is it possible to handle it in manifest that in this case C should open again or do I have to care it by myself (e.g. via SharedPreferences?)

Jing Li
  • 14,547
  • 7
  • 57
  • 69
JanScott
  • 265
  • 1
  • 5
  • 14

1 Answers1

1

This behavior can be controlled in the manifest via android:launchMode.

See here: https://developer.android.com/guide/topics/manifest/activity-element.html#lmode and more explanation here: https://developer.android.com/guide/components/tasks-and-back-stack.html

for your scenario, you'd want to keep C and route new intents to the existing instance of it, so this might work:

<activity
   android:name="A"
   ...
   android:launchMode="singleTask" />
<activity
   android:name="B"
   ...
   android:launchMode="singleTask" />
<activity
   android:name="C"
   ...
   android:launchMode="singleTask" />
marmor
  • 27,641
  • 11
  • 107
  • 150
  • Wont work. after pressing the app icon and app gets back from background, A will be started. A B and C are already "singleTask" – JanScott Dec 01 '16 at 13:05
  • try "singleInstance" then, pressing the app icon probably started a new task altogether instead of using the existing task – marmor Dec 01 '16 at 13:29
  • ah, another option - try removing launchMode from all 3 activities, Android may bring A to the top of the task when relaunched because of the custom launchModes, "standard" (or no launchMode at all) shouldn't behave like that – marmor Dec 01 '16 at 13:32