3

I've been watching some android tutorial and I've seen these two(SharedPreferences and onSavedInstanceState) and I'm confused on what to use. Can somebody explain it?

Lalit Kumar B
  • 47,486
  • 13
  • 97
  • 124
Errol Paleracio
  • 614
  • 1
  • 7
  • 21

1 Answers1

5

SharedPreferences are the approach to persist (save) simple data (name/value) across app runs - that is the data is saved after the app ends (terminated). This approach is intended to manage simple user data.

See http://developer.android.com/guide/topics/data/data-storage.html#pref

onSaveInstanceState is an activity lifecycle method to save data that can be restored later using the onRestoreInstanceState method - only while the app is in memory (not terminated). This approach is intended for managing activity state.

See http://developer.android.com/training/basics/activity-lifecycle/recreating.html

Dave Truby
  • 193
  • 1
  • 5