Android launchMode

当我按下 Home 键再切回来,会发生什么?https://juejin.im/post/6883741254614515720

Understand Android Activity's launchMode: standard, singleTop, singleTask and singleInstance https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en 

https://stackoverflow.com/questions/2417468/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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值