android intent singletask,android – launchMode =“singleTask”不会创建新任务

我有2个活动:活动A和活动B.活动A的启动模式是标准的,活动B的启动模式是singleTask.

android:name=".AActivity"

android:label="@string/app_name"

android:launchMode="standard">

android:name=".BActivity"

android:label="@string/app_name"

android:launchMode="singleTask">

我启动了应用程序,启动器启动了活动A.然后我按下主页按钮并返回到手机的主屏幕.然后我启动浏览器应用程序并输入以下内容:

dd://b

打开活动B.系统导航到我的应用程序并在活动A之上启动活动B.此时,如果我按回按钮,活动B将弹出,我看到活动A.

这不是我所期望的,因为android文档说明:

For singleTask activities,the system creates a new task and instantiates the activity at the root of the new task. However,if an instance of the activity already exists in a separate task,the system routes the intent to the existing instance through a call to its onNewIntent() method,rather than creating a new instance. Only one instance of the activity can exist at a time.

我从这些句子中理解的是,在我的情况下,因为活动B的实例不存在,所以应该启动一个新任务,它应该只有活动B在它的堆栈(我的应用程序的另一个实例应该仍然存在于单独的任务,它的堆栈中应该有活动A.然后,如果我在活动B时按回,因为它是后台堆栈中的唯一活动,它会弹出并且系统返回到浏览器.

为什么不是这样的? android系统如何知道我的应用程序是打开并导航到它并在现有应用程序堆栈上启动活动B而不是启动我的应用程序的另一个实例并让我的应用程序的两个实例拥有自己的堆栈?在新任务中实例化活动意味着什么?谁能解释一下?

谢谢.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值