android重新打开应用程序,关于安卓应用后台运行后,重新进入,应用重新打开问题...

现象:安卓应用,通过安卓自带的程序安装器安装完成以后,点击“打开按钮”,打开程序后,点击手机home键返回桌面,再次点击桌面应用图标打开应用,观察现象--应用重启,应用入口activity重新启动。

分析:通过程序安装器打开应用的方式与桌面图标打开应用的方式是有区别的。具体差别为,通过程序安装器打开应用,安卓启动应用的时候,会有一个setPackage的行为,因为这个setPackage的行为,会导致最后应用入口activity打开的时候,会传值一个FLAG_ACTIVITY_BROUGHT_TO_FRONT过来,导致应用的程序栈发生改变,从而导致后续现象的发生。

FLAG_ACTIVITY_BROUGHT_TO_FRONT官方描述如下:If, when starting the activity, there is already a task running that starts with this activity, then instead of starting a new instance the current task is brought to the front. The existing instance will receive a call to Activity.onNewIntent() with the new Intent that is being started, and with the Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT flag set. This is a superset of the singleTop mode, where if there is already an instance of the activity being started at the top of the stack, it will receive the Intent as described there (without the FLAG_ACTIVITY_BROUGHT_TO_FRONT flag set). See the Tasks and Back Stack document for more details about tasks.

注意黑色字体。这就是造成该现象发生的关键点。

解决方法如下图:

3c1a35e3d44d

增加flag判断

that's all-------------------------------------------------------------------------------------------------------------------------------

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值