Rahul Dayal Sharma wrote:Hi Joel,
Can you please explain as to when should one use Fragments and when to use Activities ?
Also, I tried creating a multi choice dialog for choosing a phone to connect via bluetooth (which turned out to be a pain on its own), but for some reason the UI look and integration took me quite a while. Does your book provide a walkthrough of the various mobile UI elements that one may require while creating mobile applications? Also, can you suggest any alternative resources for these as the android website although informative, lacks the step by step guidance required for people who are new to android and trying to self learn the fundamentals.
did you know that the fragment always needs an underlying activity?
I would use a fragment when you need o scale the app for a tablet following the famous master detail pattern
said that two activities can communicate really easy between them launching intents, implicit and explicit, for fragment if you do not use a third part library
the communication is completely different and usually follow a programmatic approach defined by a FragmentManager function.
You learn with the experience if you need activities or fragments, there is also an instinctive component, generally speaking activities are simpler because a fragment add a layer, a new level of complexity and a cycle that is different by the one of the underlying activity. Fragment allow you to fill also a small part of the screen, while instead activities take with their extension an entire screen, this is way fragment shine in tablets, where there is more space and you can simply "frame" part of the screen with some specific content, and make different part of the screen communicate using fragments