On Fri, Feb 18, 2011 at 5:19 AM, davemac <[email protected]> wrote:

> I had seen and appreciate the putFragment() method of FragmentManager.
> Quick follow-on question on that: you aren't necessarily guaranteed to
> get back the same in-memory instance of a fragment saved with
> putFragment() when you call getFragment(), but you won't be able to
> tell the difference, unless you've used internal variables and not
> saved/restored them in onSaveInstanceState() and one of the startup
> callbacks, correct?
>

Correct, you won't get back the same instance, and should not do anything
that relies on it being the same instance when your own fragment/activity is
being created.


> If fragment A wants to communicate with fragment B, I'm assuming that
> fragment A must know whether or not fragment B is part of the current
> activity, or would be in a separate activity (in the case this is
> running on a smaller screen, or just because). Is that also true? I'm
> assuming that a fragment manager is per activity, and that a fragment
> in a different activity should not be directly "talking" to a fragment
> in the first activity.
>

You should never, ever get yourself into a situation where two fragments
have references to each other but are not part of the same activity.  So
yes, there is one FragmentManager instance per activity.  Activity is still
the high-level self-contained object that others only indirectly interact
with (through startActivity() etc); FragmentManager and Fragment are
implementation details within a particular activity, making it easier to
build more complicated activities.

-- 
Dianne Hackborn
Android framework engineer
[email protected]

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.

-- 
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