我使用的是singleTop活动通过onNewIntent().
I'm using a singleTop Activity to receive intents from a search-dialog via onNewIntent()
.
我注意到的是,的onPause()
之前 onNewIntent称为()
,然后再把它调用 onResume()
。目测:
What I noticed is that onPause()
is called before onNewIntent()
, and then afterwards it calls onResume()
. Visually:
的onPause()
onNewIntent()
onResume()
search dialog initiated
search intent fired to activity
onPause()
onNewIntent()
onResume()
现在的问题是,我在 onResume注册的侦听器()
在的onPause得到删除()
,但他们所需要的 onNewIntent()
呼叫内。有没有一种标准的方式来使这些听众提供?
The problem is that I have listeners registered in onResume()
that get removed in onPause()
, but they are needed inside of the onNewIntent()
call. Is there a standard way to make those listeners available?
onNewIntent()
是指为切入点singleTop它已经在堆栈上运行其他地方活动,因此不能称之为的onCreate()
。从观活动的生命周期角度它因此,需要调用的onPause()
在 onNewIntent()
。我建议你重写你的活动不使用这些监听器里面的 onNewIntent()
。例如大部分的时间我 onNewIntent()
方法只是看起来是这样的:
onNewIntent()
is meant as entry point for singleTop activities which already run somewhere else in the stack and therefore can't call onCreate()
. From activities lifecycle point of view it's therefore needed to call onPause()
before onNewIntent()
. I suggest you to rewrite your activity to not use these listeners inside of onNewIntent()
. For example most of the time my onNewIntent()
methods simply looks like this:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// getIntent() should always return the most recent
setIntent(intent);
}
随着 onResume所有安装逻辑发生()
利用 getIntent()
。