Reputation: 41
If we have 2 activities, A
and B
, both defined as singleTask
in AndroidManifest.xml
, when A
starts B
, A will be closed (onDestroy()
being called immediately). Why does this happen, and how to avoid A
to be closed by the system (multiple singleTask
activities in same application)?
Upvotes: 4
Views: 4874
Reputation: 14174
From what I have tested onDestroy does not fire on Android 5.1
Upvotes: 0
Reputation: 14042
I had same problem.I set launch mode for activity B as "singleInstance",it solved the problem.
Upvotes: 0
Reputation: 9597
"singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack.
Since there cannot be two root activities in the system, all the previous activities are closed when starting such a task.
Upvotes: 5
Reputation: 95626
Can you provide example code and the manifest that exhibits this problem? In order to reproduce it I've created a simple 2-Activity application where both activities have launchMode="singleTask" and where the Activit1 launches Activity2. This works as expected (Activity1 is not immediately destroyed). I imagine that you are doing something else either in your code or in your manifest that causes the behavior you are describing. Please post code and manifest so we can help with your problem.
Upvotes: 1