onNewIntent() lifecycle and registered listeners

前端 未结 2 2022
生来不讨喜
生来不讨喜 2020-11-29 15:56

I\'m using a singleTop Activity to receive intents from a search-dialog via onNewIntent().

What I noticed is that onPause() is called before onNew

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 16:27

    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);
    }
    

    With all setup logic happening in onResume() by utilizing getIntent().

提交回复
热议问题