Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Fragments can seem like more code up front (since you're putting a view in a fragment, and a fragment in an Activity, instead of just a view in an Activity), but they're great at saving you from headaches in just this kind of situation- Definitely go with Fragments. They even handle the transitions for you. </p> <p>We have some sample code called "Honeycomb Gallery" you can take a look at <a href="http://developer.android.com/resources/samples/HoneycombGallery/index.html">here</a>, which has a two-column-plus-actionbar layout, and the ability to show/hide the leftmost column. This should give you a good head start in figuring out how to do layout for multiple fragments and show/hide them.</p> <p>FYI, one important trade-off to using multiple fragments in an Activity instead of multiple Activities, is that fragments don't directly respond to intents - For instance, if you had a note-taking app where "View Note" page was an Activity, and you changed it so that there was a "view note" Fragment inside the main Activity, then you'd have to set it up such that the main Activity received a note ID AND a note action (create, view, edit, whatever) in the Intent, as opposed to just having the "view note" activity receive the note ID in the Intent. The main Activity would then need to set up the fragments on the page accordingly. Not a huge deal, but if external accessibility to various parts of your application via Intent is important, then it might be easier to break your app out into a few Activities, as well as use fragments to represent the individual components.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COThanks Alexander that is a good pointer, I actually had forgotten about that Sample app. To me it is less about Activites vs Fragments and more about when to use one Activity containg static Fragments and when to dynamically load the Fragments. I think one good pattern out outline is the Intent mechanism. So if you want the screen to be addressable via an Intent then have it in it's own Activity. Can you think of other patterns? Will the Ice Cream Sandwich Core apps have good patterns in them that one can use to study how to use Fragments best?
      singulars
    2. COAt a recent Honeycomb Android Dev Lab, we had one dev say they go by "what would gmail do". While what works in your app is always most important, they do raise a good point in that the gmail app (both tablet and phone) is a very solid reference in terms of good use of fragments, and updating both Action Bar items and visible fragments based on context (i.e, actionbar items change based on whether you're reading an email, writing one, or browsing a list of emails.) In Honeycomb, Youtube & Contacts, also awesome. Per ICS, I can't talk about details just yet :)
      singulars
    3. COThanks for the great update Alexander. I am looking forward to the ICS Open Source Drop to have a look at the code. I know many of the Google Apps aren't included but I believe there are still enough core apps in the open source tree to learn a lot.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload