Search code examples
androidsaveonresumeonpause

How to save my data when I leave an android application


I know how to save and restore an application with OnPause and OnResume. I did when the user press the back button, when he turn the tablet and when he press the home button. But my problem is I don't know how to do the same when the user turn off the application.

So I would like to know how to restore my app at the same state, it was when the user turn off the app? At what moment I save the state?

Thank you very much for your help !


Solution

  • The simplest data storage you can use is SharedPreferences.

    Some examples you can find here:

    https://developer.android.com/guide/topics/data/data-storage.html#pref

    Android Shared preferences example