6

I have 7 activites all with back and forth navigation buttons between the rest; activites consist of editTexts, Spinners, textViews, TimePickers, DatePickers, and checkboxes.

I want all UI to be present and saved through navigation of an application instance; however on application termination everything needs to default.

My 8th activity collects all UI and places into an email . . .fyi

I have read alot about both onSavedInstanceState & SharedPreferences way of saving the data as activities go back and forth . . .

Which would be better for me?

SLYtiger
  • 81
  • 1
  • 6

2 Answers2

13

It will depend on how you want to manage the data. Both options (and more) are feasible:

  • If you want to fill once and keep the data even if the app gets killed, use SharedPreferences.
  • If it's volatile data that will have to be reentered differently some other time (i.e., days later), then use onSavedInstanceState.
  • If you want to keep multiple datasets on the same device, then use a SQLiteDatabase
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • Once someone follows the path of data entry I have designed (always in one instance of the app) they email the data, as soon as they email it I no longer need any record of data so I believe onsavedinstancestate state will work thank you! – SLYtiger May 05 '11 at 17:26
12

SharedPreferences

  • Use for things that should always be remembered, no matter if the phone is turned off (eg for settings chosen in the settings screen of your app

onSavedInstanceState

  • Use this for remembering things about the current state of your activity such as the currently selected tab on the screen. This allows you to recreate the same state after a rotation or if the app was killed due to low memory.
  • The things saved in onSaveInstanceState will be forgotten after reboot, and when starting a new instance of an activity they will not be passed, so they are only for remembering the state of the activity

onRetainNonConfigurationInstance

  • Use this for storing objects which take a long time to load so that you don't have to load them again when the phone is rotated.
Joseph Earl
  • 23,351
  • 11
  • 76
  • 89
  • Once someone follows the path of data entry I have designed (always in one instance of the app) they email the data, as soon as they email it I no longer need any record of data so I believe onsavedinstancestate state will work thank you! – SLYtiger May 06 '11 at 05:41