user2251607
user2251607

Reputation: 19

Saving & restoring with Bundle

I've implemented saving (onSaveInstanceState) & restoring (onCreate) through Bundle. It works when activity is recreated due to the change of orientation but it doesn't work when activity is recreated after the other apps claimed resources. In this case it turns out that my data keys in bundle are absent. Why? I am at a loss.

Upvotes: 1

Views: 255

Answers (1)

Simon
Simon

Reputation: 14472

The Bundle saved in onSaveInstanceState() and passed back in through onCreate() is not persistent and is only designed for saving state during configuration changes and Activity recreation during the lifetime of your app.

If your app is destroyed, as appears to be happening here, you will need to store your values somewhere persistent, for example in SharedPreferences

Use onPause() and onResume() to save and restore.

http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)

Upvotes: 1

Related Questions