![Page 1: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/1.jpg)
Tackling Android Fragmentation
Dev:Mobile 2012 @Glennbech , Inmeta consulting
16 klocs – not rocket science
![Page 2: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/2.jpg)
Source: Twitter / http://en.wikipedia.org/wiki/Mobile_operating_system#Market_share
![Page 3: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/3.jpg)
![Page 4: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/4.jpg)
![Page 5: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/5.jpg)
Nairobi
![Page 6: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/6.jpg)
![Page 7: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/7.jpg)
HTC 3G SLIDE
On saleMay 2010
Got GingerbreadMay 2011
X
![Page 8: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/8.jpg)
Situation report June 2012Situation report June 2012
Android
• ICS 7.3% (All versions)
• Honeycomb 2.7%
• Gingerbread (2.3) dominant @ 65%
• Froyo (2.2) still at 19.1 %
• As of February 2012 Phones with no ICS upgrade plan still sold
• This will continue
iOS
• 61% on iOS 5 or above in 15. days!
Source: http://developer.android.com/resources/dashboard/platform-versions.html
![Page 9: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/9.jpg)
WHO CARES?
![Page 10: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/10.jpg)
![Page 11: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/11.jpg)
![Page 12: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/12.jpg)
AgendaAgenda
«Prove that it is feasable, and not overly difficult to, write single APK, native android apps that works well across android versions and form
factors»
![Page 13: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/13.jpg)
ICS/Honeycomb
tabs
ActionBar& Home
Navigation
Action Items
ViewPager
https://play.google.com/store/apps/details?id=com.glennbech.nutrinfo
![Page 14: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/14.jpg)
ContextualActionbar
https://play.google.com/store/apps/details?id=com.glennbech.nutrinfo
Tab Navigation
… with ListView
multiselect
![Page 15: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/15.jpg)
https://play.google.com/store/apps/details?id=com.glennbech.nutrinfo
![Page 16: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/16.jpg)
Android versions
![Page 17: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/17.jpg)
Situation report June 2012Situation report June 2012
Android
• ICS 7.3% (All versions)
• Honeycomb 2.7%
• Gingerbread (2.3) dominant @ 65%
• Froyo (2.2) still at 19.1 %
• As of February 2012 Phones with no ICS upgrade plan still sold
• This will continue
iOS
• 61% on iOS 5 or above in 15. days!
Source: http://developer.android.com/resources/dashboard/platform-versions.html
![Page 18: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/18.jpg)
Androidmanifest.xmlAndroidmanifest.xml
<uses-sdk android:minSdkVersion=”7"android:targetSdkVersion="14” />
![Page 19: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/19.jpg)
Example. Hello worldExample. Hello world
public class TargetSDKVersionExample extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
}
![Page 20: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/20.jpg)
Example. Menu.xmlExample. Menu.xml
<menu >
<item android:id="@+id/menu_save«
android:icon="@drawable/ic_menu_save"
android:title="@string/menu_save"
android:showAsAction="ifRoom|withText" />
</menu>
![Page 21: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/21.jpg)
ICS Gingrerbread
![Page 22: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/22.jpg)
Androidmanifest.xmlAndroidmanifest.xml
<uses-sdk android:minSdkVersion=”7"android:targetSdkVersion="10” />
![Page 23: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/23.jpg)
ICS Gingrerbread
![Page 24: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/24.jpg)
Android Support LibrariesAndroid Support Libraries
• Official Android 3 & 4 features backported
• Very simple to use; download using SDK manager and include JAR file in project Includes
• Fragment API & DialogFragment
• Loader API
• ViewPager, Pager Adapter & FragmentPagerAdapter
• SearchView
• Simple Actionbar implementation provided in samples
source: http://developer.android.com/sdk/compatibility-library.html#SettingUp
![Page 25: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/25.jpg)
Limitations of the support librariesLimitations of the support libraries
• No action bar
• Code «infection»
• Cannot extend MapActivity since you have to extends custom Activity class
![Page 26: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/26.jpg)
ActionbarSherlockActionbarSherlock
• Written by Jake Whorton
• Easy to use (git clone)
• Includes & based on support libraries
• Elaborate. Support for wide range of Honeycomb and ICS features
• Actionbar
• Navigation Modes, Tabs and spinners in the action bar.
• Contextual Action Bar / ActionMode The ICS feature "split action bar“
• Plugin for MapActvity (!)
• www.actionbarsherlock.com
• Apache License Version 2.0
![Page 27: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/27.jpg)
ActionbarSherlock #1 IDEActionbarSherlock #1 IDE
![Page 28: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/28.jpg)
Hello worldHello world
![Page 29: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/29.jpg)
![Page 30: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/30.jpg)
A quick summary A quick summary
• We have used the support libraries, through ActionBarSherlock to get ICS looking apps on pre-ICS phones (back to 1.6 supported)
• The price
• Must use a custom theme
• Must extends SherlockActivity classes
• Must use overloaded methods, and use getSuppportMenuInflater() etc.
![Page 31: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/31.jpg)
Fragments
![Page 32: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/32.jpg)
Fragments crash courseFragments crash course
WHAT
• Introduced in Android 3.0
• Reusable UI components
• Have their own lifecycle
• Can add their own items to actionbar etc.
WHY
• Code Reuse
• Fragments are integrated into the ICS SDK
![Page 33: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/33.jpg)
Why - ReuseWhy - Reuse
http://developer.android.com/guide/topics/fundamentals/fragments.html
![Page 34: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/34.jpg)
Actionbar uses TabListeners for tab navigation
onTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
Source: http://developer.android.com/reference/android/app/ActionBar.TabListener.html
![Page 35: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/35.jpg)
Using fragments - example Using fragments - example
• Declared in layout
• Added/removed from code using FragmentManager
![Page 36: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/36.jpg)
Extreme client programming
![Page 37: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/37.jpg)
Density and Size Density and Size
![Page 38: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/38.jpg)
HTC Sensation
Button (100dpx100dp)
![Page 39: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/39.jpg)
Samsung Galaxy Tab 10.1
![Page 40: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/40.jpg)
Huawei IDEOS
![Page 41: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/41.jpg)
Definitions Definitions
• xlarge screens are at least 960dp x 720dp.
• large screens are at least 640dp x 480dp.
• normal screens are at least 470dp x 320dp.
• small screens are at least 426dp x 320dp
![Page 42: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/42.jpg)
Best Match layout picking Best Match layout picking
• Excellent support for providing resources based on device configuration
• Versions
• mcc310-mnc004 (US/Verizon)
• Car/desk (docking)
• Night mode
• ETCSource: http://developer.android.com/guide/topics/resources/providing-resources.html
![Page 43: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/43.jpg)
In practiceIn practice
• Provide differnet layout for different screens and orientations - backed by the same activity
• Provide a different Activity class for a different device/layout. Example one for phone and one for tablet
![Page 44: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/44.jpg)
![Page 45: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/45.jpg)
Dispatch Activity idiomDispatch Activity idiom
DispatchActivity
(condition)
PhoneActivity
TabletActivity
Intent
New Intent
New Intent
![Page 46: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/46.jpg)
![Page 47: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/47.jpg)
ConclusionConclusion
• The Android OS and devices are both forward- and backwards compatible in regard to OS versions
• Android has excellent support for layout on devices with different screen sizes and densities
• By using the ActionbarSherlock/Fragment activities you can write code that use fragments and deploy on tablets and phones
• By using ActionbarSherlock you can get the «ICS look» on your Android 1.X + devices today. Including the kindle fire.
![Page 48: Tackling Android Fragmentation Dev:Mobile 2012 @Glennbech, Inmeta consulting 16 klocs – not rocket science](https://reader036.vdocument.in/reader036/viewer/2022062621/551c5559550346b1458b4f52/html5/thumbnails/48.jpg)
“I am an old man and have known a great many troubles, but most of them never happened” – Mark Twain