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
In android, there is no concept of closing an app. The user just leaves: this is the only event that you will be aware of (onPause() in an activity). You should design your app so that it fits this lifecycle.
Typically, you should save any changes immediately but asynchronously, so that the UI doesn't hang. This is much better than saving changes in onPause() because if something bad happens before the app is paused (the app crashes, the user runs out of battery), all data was already saved properly.
SharedPreferences already save changes asynchronously so if you use that, you have nothing else to do. Otherwise you can use Kotlin coroutines or if you use Java, the good old AsyncTask is great.