I was wondering, when is the suitable time to save our application settings to SharedPreferences. Should we do it during onStop, or onDestroy? I realize both methods have their pros and cons.
onStop
If user intention is not quitting the application, save application settings to SharedPreferences just seem to be redundant. He merely press home (onStop called) -> long press home -> relaunch application by select the application again
onDestroy
User can kill the application by press home (onStop called) -> long press home -> swipe left on the application to kill it. If user quit the application by that way, I realize onDestroy is not being called although the app is killed. Hence, application settings is not being saved.
So, is it better to save the application settings, during onStop or onDestroy?
onStop()noronDestroy()will be called, as stated belowonPause()is the safest "clean up" method to use. - SamonStop, butonStopis not guaranteed to be called... - Cheok Yan Cheng