Can a fragment hold on to local variables?

Skip to first unread message

Satya Komatineni

Feb 17, 2011, 4:09:01 PM2/17/11
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

Dianne Hackborn

Feb 17, 2011, 4:21:38 PM2/17/11
to, 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
To unsubscribe from this group, send email to
For more options, visit this group at

Dianne Hackborn
Android framework engineer

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
0 new messages