I'm using a singleTop Activity to receive intents from a search-dialog via onNewIntent()
.
What I noticed is that onPause()
is called before onNewIntent()
, and then afterwards it calls onResume()
. Visually:
onPause()
onNewIntent()
onResume()
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?
This question is related to
android
android-intent
lifecycle
Note: Calling a lifecycle method from another one is not a good practice. In below example I tried to achieve that your onNewIntent will be always called irrespective of your Activity type.
OnNewIntent() always get called for singleTop/Task activities except for the first time when activity is created. At that time onCreate is called providing to solution for few queries asked on this thread.
You can invoke onNewIntent always by putting it into onCreate method like
@Override
public void onCreate(Bundle savedState){
super.onCreate(savedState);
onNewIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
//code
}
Source: Stackoverflow.com