我正在使用 singleTop Activity 通过以下方式接收来自搜索对话框的意图onNewIntent() http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29.
我注意到的是onPause()
之前被调用onNewIntent()
,然后它调用onResume()
。视觉上:
- 搜索对话框已启动
- 搜索意图激发到活动
onPause()
onNewIntent()
onResume()
问题是我已经注册了听众onResume()
被删除的onPause()
,但它们内部需要onNewIntent()
称呼。是否有一种标准方法可以让这些听众可用?
onNewIntent()
意味着作为 singleTop 活动的入口点,该活动已经在堆栈中的其他位置运行,因此无法调用onCreate()
。从活动生命周期的角度来看,因此需要调用onPause()
before onNewIntent()
。我建议您重写您的活动,不要在其中使用这些侦听器onNewIntent()
。例如大多数时候我的onNewIntent()
方法看起来就像这样:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// getIntent() should always return the most recent
setIntent(intent);
}
所有设置逻辑都发生在onResume()
通过利用getIntent()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)