Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save application state on Android [duplicate]

Tags:

android

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?

like image 248
Android_programmer_camera Avatar asked Dec 27 '11 03:12

Android_programmer_camera


People also ask

How do you save on state of application?

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.

Which of the following is appropriate for saving the state of Android application?

onPause() is the appropriate for saving the state of an Android application.

How do you save an activity state?

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.

How do you restore the state of an Android activity?

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.


1 Answers

You must override the onSaveInstanceState method. You can use preferences or SQLite, too.

Here's your exact duplicate question with code samples.

  • How do save an Android Activity state using save instance state?
like image 72
Tomislav Markovski Avatar answered Sep 21 '22 15:09

Tomislav Markovski