Android SingleTask启动模式与Home键的问题

我们知道SingleTask模式对于Activity的影响如下:

例如我们将Activity A设置为SingleTask模式,其他的Acitivity设置为Standard模式,则有以下效果:

A -> B -> C -> D 我们将Activity A一直跳转到Activity D,如果此时D -> A,则会发生Activity B,C,D都会被pop出栈中Activity A则会显示到栈顶。

我利用这个特性时,处理单端登录:将将Activity A设置成SingleTask模式,并设置成启动的Acitivity,

如果后台告知账号在其他地方登录了,则此时直接将跳转Activity A即可,其他的Acitivity都会被pop出去。

现在问题就来了,我们将App的启动的MainActivity设置为SingleTask模式时,如果我们在App跳转到Activity B时,按下Home键,此时点击App Icon,

此时不是显示Activity B,还是直接会显示Activity A,即是把A上面的Activity都会被pop出去,Activity A显示到栈顶,但这不是我想要的。

问题描述:

My main activity A has as set android:launchMode="singleTask" in the manifest. Now, whenever I start another activity from there, e.g. B and press the HOME BUTTON on the phone to return to the home screen and then again go back to my app, either via pressing the app's button or pressing the HOME BUTTONlong to show my most recent apps it doesn't preserve my activity stack and returns straight to A instead of the expected activity B.

Here the two behaviors:

Expected: A > B > HOME > B
Actual: A > B > HOME > A (bad!)

如何处理呢:

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

 

链接:https://stackoverflow.com/questions/2417468/android-bug-in-launchmode-singletask-activity-stack-not-preserved

 

转载于:https://www.cnblogs.com/hbolin/p/11479019.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值