Activity 有一个 onNewIntent(Intent intent)回调方法
This is called for activities that set launchMode to “singleTop” in their package, or if a client usedthe Intent.FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity. In either case, when the activityis re-launched while at the top of the activity stack instead of a new instance of the activity beingstarted, onNewIntent() will be called on the existing instance with the Intent that was used to re-launchit.An activity will always be paused before receiving a new intent, so you can count on onResume being calledafter this method.Note that getIntent still returns the original Intent. You can use setIntent to update it to this newIntent.
上文大概意思如下:
该方法被启动模式设置为“singleTop”的 Activity 回调,或者当通过设置 Intent.FLAG_ACTIVITY_SINGLE_TOP的 Intent 启动 Activity 时被回调。 在任何情况下, 只要当栈顶的 Activity 被重新启动时没有重新创建一个新的 Activity实例而是依然使用该 Activity 对象,那么 onNewIntent(Intent)方法就会被回调。当一个 Activity 接收到新 Intent 的时候会处于暂停状态,因此你可以统计到 onResume()方法会被再次执行,当然这个执行是在 onNewIntent 之后的。注意:如果我们在 Activity 中调用了 getIntent()方法,那么返回的 Intent 对象还是老的 Intent(也就是第一次启动该 Activity 时的传入的 Intent 对象),但是如果想让 getIntent()返回最新的 Intent,那么我们可以通过setIntent(Intent)方法设置。