onNewIntent() lifecycle and registered listeners

前端 未结 2 2020
生来不讨喜
生来不讨喜 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:22

    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
    }
    

提交回复
热议问题