50

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Android_programmer_camera
  • 13,197
  • 21
  • 67
  • 81

1 Answers1

23

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

Here's your exact duplicate question with code samples.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tomislav Markovski
  • 12,331
  • 7
  • 50
  • 72
  • 1
    Absolutely correct. And to elaborate: you can certainly "save state" with sharedPreferences and/or with SQLite. But in this case, Android "Bundles" are your friend. – paulsm4 Dec 27 '11 at 03:26
  • Do you need to implement the override method in a custom `Application` subclass? – Eido95 Nov 09 '16 at 13:09
  • 1
    @Eido95: No, the method override is on your Activity class. See the documentation for it. https://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle) – Tomislav Markovski Nov 11 '16 at 08:40