javaandroidkotlinandroid-activity

Android : Call function when user close app from any activity


I want to call one function when the user closes the app from any activity. For e.g. the user opens the app and uses it for some time and then clicks on the home button and closes the app at that time I want to call one method.

How can I archive this.?

Currently I used onDestroy method for the call function but seems like it does work for me


Solution

  • @Override
    protected void onDestroy(){
        super.onDestroy();
        callFunction();
    }
    

    Try this.