Sandro L
Sandro L

Reputation: 1150

Keep state of Activity UI after leaving and reentering it in Android-App

In my Android App I have a main activity and some other activities. The others get started with a button from the main one.

When I enter an activity and for example toggle some toggleViews, return back to main view and then again enter the sub activity, all the changes are lost.

Changing the manifest.xml to

    <activity android:name="MySubActivity"
            android:launchMode="singleTask" >
    </activity>

does not help.

Also the Methods onSaveInstanceState and onRestoreInstanceState do not work because the sub activity gets killed as soon as I leave it. So the data is saved but it can never be loaded because the Bundle of onCreate(Bundle savedInstanceState) seems to be always null.

How can I keep the status of all the inputs (better) or prevent the activity from getting killed (worse)?

Upvotes: 1

Views: 422

Answers (1)

Warpzit
Warpzit

Reputation: 28162

Save data somewhere persistent, like database, preferences, serialized objects. You are starting a new activity not restarting the old one.

Upvotes: 4

Related Questions