Android: Is onPause() guaranteed to be called after finish()?

前端 未结 4 1232
一整个雨季
一整个雨季 2021-01-17 19:09

Couldn\'t find a solid answer to this anywhere. I have a method where finish() is being called, and onPause() is called afterward.

Is onPause() guaranteed to be cal

4条回答
  •  遥遥无期
    2021-01-17 20:10

    It is a bit late but may help future visitors.

    I faced the problem of onPause() not being called when I tried to make an splash screen for my app following this tutorial.

    After some fiddling around and forcing my mind I figured out why! the onCreate() method looks like this:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
    

    So before the activity gets a chance to get started or resumed I was forcing it to be finished and so bypassing the other state method calls!

    But as far as I know from the official Activity documentation in any other situation (at least normal ones!) the onPause() method is guaranteed to be called!

提交回复
热议问题