2013年4月25日星期四

onNewIntent() lifecycle and registered listeners


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 callsonResume(). Visually:
  • search dialog initiated
  • search intent fired to activity
  • 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?


onNewIntent() is meant as entry point for singleTop activities which already run somewhere else in the stack and therefor can't call onCreate(). From activities lifecycle point of view it's therefore needed to call onPause() before onNewIntent(). I suggest you 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);
}
With all setup logic happening in onResume() by utilizing getIntent().

1 条评论:

  1. Play Slots For Fun - KongPintar.com
    Fun online casino games on your phone. 온카지노 You can 메리트 카지노 try different slot machine games 바카라 사이트 for free online or for real money. Enjoy great slots & free

    回复删除