Fighting Fragmentation with Fragments     Optimizing Android apps for Honeycomb and beyond                      Andreas Gr...
Andreas Grunewald               http://grunewaldsrobots.comgoo.gl/b3bu6
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: Androi...
What problems do Developers see?5. Ability to get paid. iOS leads here too, followed by BlackBerry.                   -For...
What problems do Developers see?4. App visibility. "iOS continues to lead," Baird reports, "followed by   Blackberry, with...
What problems do Developers see?3. Ease of development. iOS outscored Android, but both were   considered far easier to de...
What problems do Developers see?2. Store fragmentation. Several developers expressed concern over   Android app store frag...
What problems do Developers see?1. Device fragmentation. 56% of Android developers said that   operating system fragmentat...
Android Orphans:Visualizing a Sad History of Support                                                                      ...
CurrentiOS Devices
CurrentAndroid Devices
Are weARE WE            ED ?
© http://www.americanprogress.org/cartoons/2008/08/081408.html
© http://emilyandroid.deviantart.com/art/Yay-we-re-doomed-173226907
Lets have a look... shall we?
Platform Dashboard (Nov 3rd)                  2.2 & 2.3 together 85.1% of the market                  (With 2.1 included e...
4.0 | 19.10                   2011                          3.2 | 15.07                          3.1 | 10.05              ...
Screen Sizes / Densities (Nov 3rd)                      89.5% Normal Screen Size                      73.8% hdpi + 23.7% m...
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●   Dia...
Action BarAndroid 3.0 and up only, not in Support Package for pre 3.0 devices
FoHelp is on the way...                                kmr                                      eo                        ...
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                http://goo.gl/y9C6c
Patterns when using FragmentsEvent Listener Interface   ●   communication between Fragment and Activity   ●   separation o...
Event Listener Interfaceclass MyActivity implements OnTitleListenerclass TitlesFragment extends ListFragment { public inte...
FrameLayoutOnly use for static initialization and Fragments that are always present<fragment android:layout_height="match_...
FrameLayoutFragmentManager fragMgr = getSupportFragmentManager();ChaptersFragment chapters = (ChaptersFragment)fragMgr.fin...
Resources●   Android Developer Portal – SDK, Sample Code, Reference Docs    http://developer.android.com●   Commonsware – ...
PeopleAlexander Lucas                                      Kirill GrouchnikovDevAdv might answer you on Stackoverflow     ...
Thank YouAndreas Grunewaldhttp://grunewaldsrobots.comTwitter: @agrunewaldGoogle+ http://goo.gl/IZzuShttp://www.linkedin.co...
Fighting Fragmentation with Fragments
Upcoming SlideShare
Loading in...5
×

Fighting Fragmentation with Fragments

3,816

Published on

A presentation for Barcamp Saskatoon 2011. The demo app

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,816
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
48
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Fighting Fragmentation with Fragments

  1. 1. Fighting Fragmentation with Fragments Optimizing Android apps for Honeycomb and beyond Andreas Grunewald Nov 2011 Barcamp Saskatoon
  2. 2. Andreas Grunewald http://grunewaldsrobots.comgoo.gl/b3bu6
  3. 3. iOS Development isso much more awesome than Android Developmemt
  4. 4. Android is way too Fragmented
  5. 5. Android is a mess, say developers - Fortune
  6. 6. Android Fragmentation: a real problem, developers say - UbergizmoDevelopers: Android Fragmentationis a “Huge” Problem -Slashgear
  7. 7. What problems do Developers see?5. Ability to get paid. iOS leads here too, followed by BlackBerry. -Forbes http://tech.fortune.cnn.com/2011/04/04/android-is-a-mess-say-developers/
  8. 8. 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 http://tech.fortune.cnn.com/2011/04/04/android-is-a-mess-say-developers/
  9. 9. 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 http://tech.fortune.cnn.com/2011/04/04/android-is-a-mess-say-developers/
  10. 10. 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 http://tech.fortune.cnn.com/2011/04/04/android-is-a-mess-say-developers/
  11. 11. 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 http://tech.fortune.cnn.com/2011/04/04/android-is-a-mess-say-developers/
  12. 12. Android Orphans:Visualizing a Sad History of Support -theunderstatement http://theunderstatement.com/post/11982112928/android-orphans-visualizing-a-sad-history-of-support
  13. 13. CurrentiOS Devices
  14. 14. CurrentAndroid Devices
  15. 15. Are weARE WE ED ?
  16. 16. © http://www.americanprogress.org/cartoons/2008/08/081408.html
  17. 17. © http://emilyandroid.deviantart.com/art/Yay-we-re-doomed-173226907
  18. 18. Lets have a look... shall we?
  19. 19. 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%
  20. 20. 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
  21. 21. Screen Sizes / Densities (Nov 3rd) 89.5% Normal Screen Size 73.8% hdpi + 23.7% mdpi = 97.5%
  22. 22. So how do you do it ?
  23. 23. FragmentsIntroduced in Android 3.0 Honeycomb. What about pre 3.0 Devices ?
  24. 24. The Support Packageaka Compatibility Library
  25. 25. Whats in it ?● Fragment● FragmentManager●● FragmentTransaction ListFragment UI● DialogFragment● LoaderManager Loader Data●● AsyncTaskLoader● CursorLoader
  26. 26. Action BarAndroid 3.0 and up only, not in Support Package for pre 3.0 devices
  27. 27. FoHelp is on the way... kmr eo nG i tH ub http://actionbarsherlock.com
  28. 28. Lets look at Fragments again
  29. 29. How do you structure an App (The pre Honeycomb way)
  30. 30. How do you structure an App (Honeycomb and beyond)
  31. 31. That doesnt look much different!? vs
  32. 32. Lets turn our phone sideways
  33. 33. How about Tablets ?
  34. 34. And of course Tablet landscape
  35. 35. So how many activites, fragments and layouts are there ?
  36. 36. Put it all together
  37. 37. So much for the theory....
  38. 38. Download the Demo App from the Market http://goo.gl/y9C6c
  39. 39. 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
  40. 40. 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); }...
  41. 41. 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" />
  42. 42. FrameLayoutFragmentManager fragMgr = getSupportFragmentManager();ChaptersFragment chapters = (ChaptersFragment)fragMgr.findFragmentById(R.id.chapters);if (chapters == null){ chapters = ChaptersFragment.newInstance(titleId); chapters.addOnChapterListener(this);}FragmentTransaction ft = getSupportFragmentManager().beginTransaction();ft.replace(R.id.chapters, chapters);ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);ft.commit();View chaptersFrame = findViewById(R.id.chapters);chaptersFrame.setVisibility(View.VISIBLE);
  43. 43. Resources● Android Developer Portal – SDK, Sample Code, Reference Docs http://developer.android.com● Commonsware – Android Ebooks, Free Sample Code http://commonsware.com/● StackOverflow – Questions and Answers http://stackoverflow.com/questions/tagged/android● Android IRC Channel #android-dev on freenode
  44. 44. 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: goo.gl/8XZbu
  45. 45. Thank YouAndreas Grunewaldhttp://grunewaldsrobots.comTwitter: @agrunewaldGoogle+ http://goo.gl/IZzuShttp://www.linkedin.com/in/andreasgrunewaldhttp://about.me/agrunewald
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×