atom feed11 messages in com.googlegroups.android-developers[android-developers] Fragment questio...
FromSent OnAttachments
davemacFeb 17, 2011 8:09 pm 
Streets Of BostonFeb 17, 2011 8:38 pm 
Dianne HackbornFeb 17, 2011 10:12 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:52 pm 
Gregg RenoFeb 27, 2011 6:57 pm 
davemacFeb 27, 2011 8:59 pm 
Dianne HackbornFeb 27, 2011 11:09 pm 
Gregg RenoFeb 28, 2011 6:42 am 
Subject:[android-developers] Fragment question: inter-fragment communication?
From:davemac (dave@gmail.com)
Date:Feb 17, 2011 8:09:54 pm
List:com.googlegroups.android-developers

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