Android: bug in launchMode=”singleTask”? -> activity stack not preserved

This is not a bug. When an existing singleTask activity is launched, all other activities above it in the stack will be destroyed.

When you press HOME and launch the activity again, ActivityManger calls an intent

{act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]flag=FLAG_ACTIVITY_NEW_TASK|FLAG_ACTIVITY_RESET_IF_NEEDED cmp=A}

So the result is A > B > HOME > A.

It’s different when A’s launchMode is “Standard”. The task which contains A will come to the foreground and keep the state the same as before.

You can create a “Standard” activity eg. C as the launcher and startActivity(A) in the onCreate method of C

OR

Just remove the launchMode="singleTask" and set FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP flag whenever call an intent to A

Leave a Comment