On Sat, Jun 19, 2010 at 1:36 PM, -DC- <diskcras...@gmail.com> wrote:
> I've got an app that uses a Spinner tied to an Adapter. I want to be
> able to save its contents when onSaveInstanceState is called, but am
> not sure which put method of the Bundle class I can use to do this?
>
>    protected void onSaveInstanceState(Bundle outState) {
>        //TODO: Figure out how to save mDirectories (spinner)
>        outState.putString("mStatus", mStatus.getText().toString());
>        outState.putString("mPath", mPath.getText().toString());
> //        outState.putSerializable("mDirectories", mDirectories); <--
> Spinner object
>        outState.putStringArray("links", links);
>        outState.putInt("linksPointer", linksPointer);
>        super.onSaveInstanceState(outState);
>    }

You do not want to put a Spinner in the onSaveInstanceState() Bundle.
Besides the fact that it is impossible, doing so would cause your new
activity to hold onto a reference to that Spinner, which holds onto a
reference to your old activity, which will cause a substantial memory
leak.

Your Spinner's contents are set via some sort of Adapter. You should
be making sure your new Activity can re-create that Adapter. Then, put
either getItemSelectedId() or getItemSelectedPosition() in the Bundle,
so you can restore the selection in the new Activity.

-- 
Mark Murphy
CommonsWare
mmur...@commonsware.com
http://commonsware.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to