Fighting Fragmentation with Fragments
Upcoming SlideShare
Loading in...5

Fighting Fragmentation with Fragments



A presentation for Barcamp Saskatoon 2011. The demo app

A presentation for Barcamp Saskatoon 2011. The demo app



Total Views
Views on SlideShare
Embed Views



5 Embeds 1,206 1202 1 1 1 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Fighting Fragmentation with Fragments Fighting Fragmentation with Fragments Presentation Transcript

  • Fighting Fragmentation with Fragments Optimizing Android apps for Honeycomb and beyond Andreas Grunewald Nov 2011 Barcamp Saskatoon
  • Andreas Grunewald
  • iOS Development isso much more awesome than Android Developmemt
  • Android is way too Fragmented
  • Android is a mess, say developers - Fortune
  • Android Fragmentation: a real problem, developers say - UbergizmoDevelopers: Android Fragmentationis a “Huge” Problem -Slashgear
  • What problems do Developers see?5. Ability to get paid. iOS leads here too, followed by BlackBerry. -Forbes
  • What problems do Developers see?4. App visibility. "iOS continues to lead," Baird reports, "followed by Blackberry, with Android still receiving poor marks in this category." Developers are particularly concerned about the level of "junk" apps in the Android ecosystem. -Forbes
  • What problems do Developers see?3. Ease of development. iOS outscored Android, but both were considered far easier to develop for than, say, Research in Motions (RIMM) BlackBerry OS or Nokia (NOK) Symbian. -Forbes
  • What problems do Developers see?2. Store fragmentation. Several developers expressed concern over Android app store fragmentation. "Generally," Baird reports, "developers seem to prefer a unified, single store experience like Apples App Store." -Forbes
  • What problems do Developers see?1. Device fragmentation. 56% of Android developers said that operating system fragmentation among the various Android devices was a meaningful or "huge" problem, a percentage that actually increased over the past three months. -Forbes
  • Android Orphans:Visualizing a Sad History of Support -theunderstatement
  • CurrentiOS Devices
  • CurrentAndroid Devices
  • Are weARE WE ED ?
  • ©
  • ©
  • Lets have a look... shall we?
  • Platform Dashboard (Nov 3rd) 2.2 & 2.3 together 85.1% of the market (With 2.1 included even 95.8%) Honeycomb only 1.9% Platform Codename API Level Distribution Android 1.5 Cupcake 3 0.9% Android 1.6 Donut 4 1.4% Android 2.1 Eclair 7 10.7% Android 2.2 Froyo 8 40.7% Android 2.3 - Gingerbread 9 0.5% Android 2.3.2 Android 2.3.3 - 10 43.9% Android 2.3.7 Android 3.0 Honeycomb 11 0.1% Android 3.1 12 0.9% Android 3.2 13 0.9%
  • 4.0 | 19.10 2011 3.2 | 15.07 3.1 | 10.05 3.0 | 22.02Android Versions 2.3 | 06.12 2010 2.2 | 20.05 2.1 | 12.01 2.0 | 26.10 1.6 | 15.09 2009 1.5 | 30.04 1.1 | 09.02 1.0 | 23.09 2008
  • Screen Sizes / Densities (Nov 3rd) 89.5% Normal Screen Size 73.8% hdpi + 23.7% mdpi = 97.5%
  • So how do you do it ?
  • FragmentsIntroduced in Android 3.0 Honeycomb. What about pre 3.0 Devices ?
  • The Support Packageaka Compatibility Library
  • Whats in it ?● Fragment● FragmentManager●● FragmentTransaction ListFragment UI● DialogFragment● LoaderManager Loader Data●● AsyncTaskLoader● CursorLoader
  • Action BarAndroid 3.0 and up only, not in Support Package for pre 3.0 devices
  • FoHelp is on the way... kmr eo nG i tH ub
  • Lets look at Fragments again
  • How do you structure an App (The pre Honeycomb way)
  • How do you structure an App (Honeycomb and beyond)
  • That doesnt look much different!? vs
  • Lets turn our phone sideways
  • How about Tablets ?
  • And of course Tablet landscape
  • So how many activites, fragments and layouts are there ?
  • Put it all together
  • So much for the theory....
  • Download the Demo App from the Market
  • Patterns when using FragmentsEvent Listener Interface ● communication between Fragment and Activity ● separation of concerns / the fragments dont know about the activities -> easier to reuse across ActivitiesUsing FrameLayouts as placeholders and adding fragmentsdynamically ● allows hiding of the viewgroup ● Fragments can be given arguments when they are needed ● easier to refactor if no fragments are in layout.xml
  • Event Listener Interfaceclass MyActivity implements OnTitleListenerclass TitlesFragment extends ListFragment { public interface OnTitleListener { public void onTitleSelected(int titleId); } public void addOnTitleListener(OnTitleListener onTitleListener) { listener = onTitleListener; } public void onListItemClick(ListView l, View v, int position, long id) { ... listener.onTitleSelected(position); }...
  • FrameLayoutOnly use for static initialization and Fragments that are always present<fragment android:layout_height="match_parent" android:layout_weight="1"android:id="@+id/titles" class="demo.gwr.fightfrag.fragments.TitlesFragment"android:layout_width="0px"></fragment>Use the framelayout for dynamic fragments, by hiding the Layout you can make the fragmentsappear when they are needed<FrameLayout android:id="@+id/chapters" android:layout_weight="1"android:layout_width="0px" android:layout_height="match_parent"android:visibility="gone" />
  • FrameLayoutFragmentManager fragMgr = getSupportFragmentManager();ChaptersFragment chapters = (ChaptersFragment)fragMgr.findFragmentById(;if (chapters == null){ chapters = ChaptersFragment.newInstance(titleId); chapters.addOnChapterListener(this);}FragmentTransaction ft = getSupportFragmentManager().beginTransaction();ft.replace(, chapters);ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);ft.commit();View chaptersFrame = findViewById(;chaptersFrame.setVisibility(View.VISIBLE);
  • Resources● Android Developer Portal – SDK, Sample Code, Reference Docs● Commonsware – Android Ebooks, Free Sample Code● StackOverflow – Questions and Answers● Android IRC Channel #android-dev on freenode
  • PeopleAlexander Lucas Kirill GrouchnikovDevAdv might answer you on Stackoverflow Android User Interface EngineerAndy Rubin Matias DuarteThe father of Android The creative mind behind Androids UI, Designed WebOSChet Haase Reto MeierAndroid Graphics Engineer Author Professional Android DevelopmentDan Morrill Romain GuyAndroid Engineer Android Graphics Engineer, Androdi WallpapersDianne Hackborn Roman NurikAndroid Framework Engineer Android Developer AdvocateEd Burnette Tim BrayAuthor Hello Android Android Developer Advocate from VancouverJake Wharton Tor NorbyeDeveloper of Action Bar Sherlock Works on the ADT & Eclipse PluginJean Baptiste Queru Xavier DucrohetAndroid Open Source Project Android Developer Tools Lead Shared Google+ Circle:
  • Thank YouAndreas Grunewaldhttp://grunewaldsrobots.comTwitter: @agrunewaldGoogle+