onSaveInstanceState() is used to save per instance state while
SharedPreferences is used to save persistent data across sessions.
Whenever you start the app the SharedPreferences are there, data saved
in onSaveInstanceState() is gone once the app has been shut down.

onSaveInstanceState() can be used e.g. to keep ui state when the
orientation of the phone changes (portrait/landscape).
While Android is doing most of the work if you call through to
super.onSaveInstanceState() (like state of buttons, focus of views
etc), there might be additional state to save and restore like the
position of sprites for a game or selection or text entered into text
input fields.

Don't use SharedPreferences over onSaveInstanceState() just because
the former is easier to implement. They are really two different
things meant for different purposes.

Cheers
Emanuel Moecklin
1gravity LLC

On Jan 20, 4:34 pm, Chris <[email protected]> wrote:
> OH.... obviously, I don't know why I was so set on using the
> savedInstance... Anyway SharedPreferences works great.
>
> Chris
>
> On Jan 20, 3:03 pm, TreKing <[email protected]> wrote:
>
>
>
>
>
>
>
> > On Thu, Jan 20, 2011 at 1:48 PM, Chris <[email protected]> wrote:
> > > I'm trying to save the state of my app while I shut it down but every
> > > time I bring it back up savedInstanceState is always null..?
>
> > If your app is shut down completely, there is no state to save.
>
> > >  I couldn't seem to find much info on calling onSaveInstanceState properly
> > > so here's what I did
>
> >http://developer.android.com/reference/android/app/Activity.html#onSa...
> > <http://developer.android.com/reference/android/app/Activity.html#onSa...)>
>
> > > onPause ()
> > > {...
> > >  Bundle test = new Bundle();
> > >  this.onSaveInstanceState(test);
> > > }
>
> > You're not supposed to be calling onSaveInstanceState - the system does this
> > for you as an indication that you are liable for axing.
>
> > --------------------------------------------------------------------------- 
> > ----------------------
> > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> > transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to