In android, I want to save data in activity A when switching to activity B and restoring that data as I switch back to it. How can I do this? Thanks in advance for any help.
Asked
Active
Viewed 40 times
0
-
1When ? That's the default behavior, when you go back to an activity you get it exactly how you left it. – Stephane Mathis Mar 27 '14 at 16:07
-
Stephane Mathis is right. also you can store your data in SharedPreferences if you want to start your activity with same data after onStop(). – Dima Mar 27 '14 at 16:13
-
I need when I turn to activity A (B--->A) I found each fields with values before I switch to activity B. – user3383728 Mar 27 '14 at 16:19
-
@Dima please how can I do this ? any tutoriel that help me ? – user3383728 Mar 27 '14 at 16:21
-
1look here: http://developer.android.com/guide/topics/data/data-storage.html#pref – Dima Mar 27 '14 at 16:23
-
my issue is how to keep values of fields when turn to activity A after calling to activity B ? – user3383728 Mar 27 '14 at 16:37
1 Answers
1
I agree with the rest, you should have all your data there, but in case it is not happening, you can always use Activity's bundle to save any data you want, and restore it (put values on the fields) when you open the activity again.
Take a look at this answer for more detail: Saving Android Activity state using Save Instance State