Can a fragment hold on to local variables?

65 views
Skip to first unread message

Satya Komatineni

unread,
Feb 17, 2011, 4:09:01 PM2/17/11
to android-d...@googlegroups.com
A fragment can be instantiated using its default constructor by the
base framework.

The initialization arguments are passed as a bundle that can be
restored and reset.

How about local variables for managing state of that fragment?

Does one need to use the bundle to insert/remove these local variables?

Or does one need to reset local variables based on lifecycle methods
and valid only for the current life of the fragment?

Appreciate your coments and help
Satya

Dianne Hackborn

unread,
Feb 17, 2011, 4:21:38 PM2/17/11
to android-d...@googlegroups.com, Satya Komatineni
If you want to keep them across instances, you need to save and restore them just like in an activity.  My blog post shows an example of this, retaining the mCurCheckPosition variable across instances.


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



--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Reply all
Reply to author
Forward
0 new messages