当主Activity设置了lauchMode为singleTask的时候, 每次长按home返回的时候都会返回到主Activity。这并不是我们想要的结果。
This is not a bug. When an existed "singleTask" activity is launching, 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] flat=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
posted on 2011-08-29 18:18
汪杰 阅读(270)
评论(0) 编辑 收藏 引用 所属分类:
Java