Is the Activity being destroyed because orientation changed or because app is closing?

后端 未结 6 1347
面向向阳花
面向向阳花 2021-01-01 21:12

I have an Activity that starts an AsyncTask. The activity is allowed to show in Portrait or Landscape orientation. When the orientation is

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-01 22:15

    you can use isFinishing() method , to check if the activity is going to be killed or onDestroy() method just called due to change in orientation

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(isFinishing()){
            Log.i("DEBUG", "App will Terminate ");
        }else{
            Log.i("DEBUG", "Orientation changed");
        }
    
    }
    

提交回复
热议问题