When the user minimizes the app (goes to the background):
onPause() preferred because it is getting called when the activity is no longer in the foreground, but still in memory. onStop() is called when the activity is no longer visible. Use onPause() only if you need to save data when the user leaves the activity, even if it’s temporarily (like when switching between activities or the app is minimized).
When the app is killed, onDestroy() is called. But, Android OS is not always aware that onDestroy() will always be called when the app is killed abruptly.
For cases like this, you can save data in onPause() or onStop() because these are more reliable for handling data persistence before the app is killed.