atom feed11 messages in[android-developers] Fragment questio...
FromSent OnAttachments
davemacFeb 17, 2011 8:10 pm 
Streets Of BostonFeb 17, 2011 8:39 pm 
Dianne HackbornFeb 17, 2011 10:13 pm 
davemacFeb 18, 2011 5:19 am 
Dianne HackbornFeb 18, 2011 10:09 am 
Gregg RenoFeb 27, 2011 6:39 pm 
Dianne HackbornFeb 27, 2011 6:53 pm 
Gregg RenoFeb 27, 2011 6:58 pm 
davemacFeb 27, 2011 8:59 pm 
Dianne HackbornFeb 27, 2011 11:10 pm 
Gregg RenoFeb 28, 2011 6:43 am 
Subject:[android-developers] Fragment question: inter-fragment communication?
From:davemac (
Date:Feb 17, 2011 8:10:17 pm

I'd love to hear opinions on the best way to communicate between fragments.

If we consider that fragments are like sub-activities (a common metaphor), then we might think to use broadcast messages to tell one fragment about something that happened in another fragment. That seems a bit difficult though not impossible.

The samples simply lookup one fragment from another then access views directly. This forces that fragment to understand what's going on around it, which doesn't feel as object-oriented as I'd like. I'd feel better if maybe the activity was doing that sort of coordination, so the fragment tells the activity, and the activity figures out which other fragment, if any, needs to get a message, then invokes a method on the fragment so it can perform any updates. Or the activity could decide we're in a situation where we need to fire up a separate activity. Or maybe move things around on the screen.

Am I over-complicating things here? I realize that a mobile app should be as compact as possible, and if that means "just do it" and access views in other fragments directly, then I could go along with that. But I thought I'd ask the group to get some other opinions.

- dave