Possible Duplicate:
How do I save an Android application's state?
I have an Android app. The app crashes in one screen and the app exits. When I launch the app again, I need to launch another screen by checking some condition in the initial activity onCreate() method. Can we do this using preferences or SQLite?
And to elaborate: you can certainly "save state" with sharedPreferences and/or with SQLite. But in this case, Android "Bundles" are your friend. Do you need to implement the override method in a custom Application subclass? @Eido95: No, the method override is on your Activity class.
onPause() is the appropriate for saving the state of an Android application.
When the activity goes into the background, the system calls onSaveInstanceState() . You should save the search query in the onSaveInstanceState() bundle. This small amount of data is easy to save. It's also all the information you need to get the activity back into its current state.
State can be restored in either the onCreate() or the onRestoreInstanceState() methods of the activity by extracting values from the Bundle object and updating the activity based on the stored values.
You must override the onSaveInstanceState
method. You can use preferences or SQLite, too.
Here's your exact duplicate question with code samples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With