Android onNewIntent


protected void onNewIntent(Intent intent)
Added in API level 1

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 calling startActivity(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.

Note that getIntent() still returns the original Intent. You can use setIntent(Intent) to update it to this new Intent.

Parameters
intentThe new intent that was started for the activity.
See Also

调用 onNewIntent  有两种情况:

第一种: 这个 Activity A设置为 SingleTop 启动模式。也就是位于栈顶就不新创建。
第二种: 启动一个 Activity A时把 Intent flag 设置为 FLAG_ACTIVITY_SINGLE_TOP 。




如果重新启动这个 Activity A,当 A 位于栈顶时(这样 A 不用新建实例),onNewIntent 将会被调用。

另外,如果有必要更新获取的 Intent,需要调用下 setIntent。这个方法一般也是和 onNewIntent 连用的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值