Android: onDestroy() or similar method in Application class

前端 未结 5 1520
清酒与你
清酒与你 2020-12-03 09:22

I am extending Application class to work with some global variables that need context. I know there is onCreate() method in the Application class that gets called before any

5条回答
  •  青春惊慌失措
    2020-12-03 10:01

    You can override onDestroy() in the Activity which will be the last one closed in your app and check if it's finishing. In this case your code will not be invoked on a device rotation. But you should be aware that onDestroy() is not invoked when an app is closed through device home button.

    @Override
    public void onDestroy(){
        super.onDestroy();
        if(isFinishing()){
            //do your stuff here
        }
    }
    

提交回复
热议问题