为啥Android返回上一页时不调用OnNewIntent方法
关于API有什么问题,可以先查阅文档。onNewIntennt文档如是说:This is called for activities that set launchMode to "singleTop" in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when callingstartActivity(Intent). In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.
An activity will always be paused before receiving a new intent, so you can count on onResume() being called after this method.
【为啥Android返回上一页时不调用OnNewIntent方法】 Note that getIntent() still returns the original Intent. You can use setIntent(Intent) to update it to this new Intent.
当Activity的启动模式是singleTop或者使用FLAG_ACTIVITY_SINGLE_TOP这个标记启动新的Activity并且Activity栈顶就是待启动的Activity的时候,会调用原Activity的这个方法;举个例子,现在Actvity A在栈顶,假设你在A界面使用Intent t = new Intent(this, A.class);t.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);startActivity(t);再次启动A的时候,并不会重新创建一个A的实例;而是直接调用一下`onNewIntent`方法。在你这种情况下,可以考虑使用startActivityForResult处理结果。
■网友
onNewIntent是当前栈顶activity继续响应intent且flag为singleTop时触发的默认是会新建一个activity并将intent传入,但是设为singleTop后,不会重新创建,而是让栈顶activity通过onNewIntent来响应。(可以看上面回答的源码注释)
■网友
因为没有 newIntent.
推荐阅读
- 禄口■南京禄口国际机场要求成都旅客“原路返回”?机场回应
- 为啥看到书柜上的藏书会有心旷神怡的感觉
- 为啥知乎上普便有一种【我在北上广深打工,所以拥有更好的视野】这样的错觉
- 为啥工商银行的用户体验如此之差
- 汽车|看了中消协4S店服务测评调查结果,终于知道法系车为啥卖不好了
- 你为啥从窝窝商城离职?
- 为啥5G和2.4G默认的BSSID是相同的
- 为啥电器实体店的价格比淘宝贵那么多
- 现在在线学习视频有很多了,为啥大部分人还是喜欢下载下来观看
- 为啥到现在你还没有女朋友 ?
