![Page 1: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/1.jpg)
Hasan Hosgel | ImmobilienScout24
Best Practices to develop the Layouts for different Android Device Classifications
![Page 2: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/2.jpg)
About Me Hasan Hosgel • developer @
ImmobilienScout24,
• CO-Organizer @ GDG Berlin Android
• Twitter / Github: alosdev
• Google+: Hasan Hosgel
![Page 3: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/3.jpg)
![Page 4: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/4.jpg)
> 3600 Android Devices
![Page 5: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/5.jpg)
Source: http://www.flickr.com/photos/hertenberger/1434191066/
![Page 6: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/6.jpg)
Device Classification
Images sources: https://play.google.com/store/devices
![Page 7: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/7.jpg)
Images sources: https://play.google.com/store/devices http://www.htc.com/de/
![Page 8: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/8.jpg)
Images sources: http://www.sony.de/hub/google-tv
![Page 9: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/9.jpg)
Images Sources https://developer.ford.com/
![Page 10: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/10.jpg)
![Page 11: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/11.jpg)
Images sources: http://www.sonymobile.com/global-en/products/accessories/smartwatch-2-sw2/
![Page 12: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/12.jpg)
Source: http://www.flickr.com/photos/paulbrigham/8452522044/
![Page 13: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/13.jpg)
Resource Folders You can use several qualifiers in the resource folders name for serving the best matching resource.
![Page 14: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/14.jpg)
Qualifiers • Language (-en) • Language & Region (-en-rUS) • Smallest Width (sw600dp) • Screensize (-small, -normal, -large) • Screen Orientation (-port, -land) • Screen Pixel Densitiy (-mdpi, -hdpi,...) • Platform Version (-v11, -v13)
![Page 15: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/15.jpg)
Best Matching Resources Win 1. res/values/strings.xml 2. res/values-en-rUS/strings.xml 3. res/values-large/strings.xml 4. res/values-sw600dp/strings.xml
The order of the qualifiers in the previous slides gives the ranking, if two resources have the same matching number of qualifiers.
![Page 16: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/16.jpg)
Images Resources • Use the different qualifiers for the screen pixel
density (mdpi, hdpi, etc.) • If you are forced to use text on images use
language and region (en, es-rUS, en-rUS, etc.) • Better approach is to use 9-patch drawables, which
stretches automatically depending on the content inside.
• You must provide different launcher icons for Froyo, Honeycomb and above? Use the platform version. (v4, v11, v14)
![Page 17: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/17.jpg)
Classifications for Layouts
Platform version at least v13
project-folder/res/
layout/ è small phones
layout-sw320dp/ è other phones
layout-sw600dp/ è tablets 7”
layout-sw720dp/ è tablets 10”
![Page 18: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/18.jpg)
Platform version at lower v11 project-folder/res/
layout/ è phones
layout-v11/ è tablets 10” layout-v13/ è small phones
layout-sw320dp/ è other phones
layout-sw600dp/ è tablets 7”
layout-sw720dp/ è tablets 10”
![Page 19: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/19.jpg)
hint The smallest width qualifier gets automatically platform version "-v13" through the packager, for avoiding problems with the number of matching qualifiers.
![Page 20: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/20.jpg)
Howto Classify In Code • Read configuration from the device • Smarter approach use boolean
resources
![Page 21: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/21.jpg)
project-folder/res/values/layouts.xml
<resources>
<bool name="is_phone_small">false</bool>
<bool name="is_phone_other">true</bool>
<bool name="is_tablet_7">false</bool>
<bool name="is_tablet_10">false</bool>
</resources>
![Page 22: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/22.jpg)
project-folder/res/values/layouts.xml
<resources>
<bool name="is_phone_small">false</bool>
<bool name="is_phone_other">true</bool>
<bool name="is_tablet_7">false</bool>
<bool name="is_tablet_10">false</bool>
</resources>
![Page 23: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/23.jpg)
project-folder/res/values/layouts.xml
<resources>
<bool name="is_phone_small">false</bool>
<bool name="is_phone_other">true</bool>
<bool name="is_tablet_7">false</bool>
<bool name="is_tablet_10">false</bool>
</resources>
![Page 24: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/24.jpg)
project-folder/res/values/layouts.xml
<resources>
<bool name="is_phone_small">false</bool>
<bool name="is_phone_other">true</bool>
<bool name="is_tablet_7">false</bool>
<bool name="is_tablet_10">false</bool>
</resources>
![Page 25: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/25.jpg)
project-folder/res/values/layouts.xml
<resources>
<bool name="is_phone_small">false</bool>
<bool name="is_phone_other">true</bool>
<bool name="is_tablet_7">false</bool>
<bool name="is_tablet_10">false</bool>
</resources>
Usage in code:
getResources().getBoolean(R.bool.is_phone_small)
![Page 26: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/26.jpg)
project-folder/res/values/layouts.xml
<resources>
<bool name="is_phone_small">false</bool>
<bool name="is_phone_other">true</bool>
<bool name="is_tablet_7">false</bool>
<bool name="is_tablet_10">false</bool>
</resources>
Usage in code:
getResources().getBoolean(R.bool.is_phone_small)
![Page 27: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/27.jpg)
Current File Structure project-folder/res/
layout/main.xml
layout-v11/main.xml
layout-v13/main.xml
layout-sw320dp/main.xml
layout-sw600dp/main.xml
layout-sw720dp/main.xml
![Page 28: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/28.jpg)
Fixing one bug in the 10" layout has to be done in two files
![Page 29: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/29.jpg)
Fixing one bug in the 10" layout has to be done in two files
è error prone
![Page 30: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/30.jpg)
Fixing one bug in the 10" layout has to be done in two files
è error prone
How to avoid this?
![Page 31: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/31.jpg)
Fixing one bug in the 10" layout has to be done in two files
è error prone
How to avoid this? - Use resource aliasing.
![Page 32: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/32.jpg)
Resource Alias
Put your layout files in the default folder.
project-folder/res/
layout/main_phone_small.xml
layout/main_phone_other.xml
layout/main_tablet_7.xml
layout/main_tablet_10.xml
![Page 33: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/33.jpg)
Resource Alias
2. Create an item with the needed classification in the previously defined values folder.
project-folder/res/values-sw720dp/
layouts.xml
<item name="main"
type="layout">@layout/main_tablet10</item>
![Page 34: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/34.jpg)
Resource Alias
2. Create an item with the needed classification in the previously defined values folder.
project-folder/res/values-sw720dp/
layouts.xml
<item name="main"
type="layout">@layout/main_tablet10</item>
![Page 35: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/35.jpg)
Resource Alias
2. Create an item with the needed classification in the previously defined values folder.
project-folder/res/values-sw720dp/
layouts.xml
<item name="main"
type="layout">@layout/main_tablet10</item>
![Page 36: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/36.jpg)
Resource Alias
2. Create an item with the needed classification in the previously defined values folder.
project-folder/res/values-sw720dp/
layouts.xml
<item name="main"
type="layout">@layout/main_tablet10</item>
![Page 37: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/37.jpg)
CODE
![Page 38: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/38.jpg)
Sample Screen
![Page 39: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/39.jpg)
Sample Screen
![Page 40: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/40.jpg)
Sample Screen
Use <includes>
![Page 41: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/41.jpg)
Usage Includes <LinearLayout … > …
<include layout="@layout/footer"/>
…
</LinearLayout>
![Page 42: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/42.jpg)
Usage Includes <LinearLayout … > …
<include layout="@layout/footer"/> …
</LinearLayout>
![Page 43: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/43.jpg)
Usage Includes <LinearLayout … > …
<include layout="@layout/footer"/> …
</LinearLayout>
![Page 44: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/44.jpg)
CODE
![Page 45: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/45.jpg)
Sample Screen
Use <includes>
![Page 46: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/46.jpg)
Sample Screen
Use <includes>
![Page 47: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/47.jpg)
Sample Screen
Use <includes>
Create custom view
![Page 48: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/48.jpg)
Custom View public class CustomView extends LinearLayout { … public CustomView(Context context, AttributeSet attrs) { … addView(createTextView(context, "label"), lp); addView(createTextView(context, "desc"), lp); if(getResources().getBoolean(R.bool.is_phone)){ setOrientation(VERTICAL); } else { setOrientation(HORIZONTAL); } } … }
![Page 49: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/49.jpg)
Sample Screen
Use <includes>
Create custom view
![Page 50: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/50.jpg)
Sample Screen
Use <includes>
Create custom view
If custom view has much more business logic and need lifecycles Create a Fragment
![Page 51: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/51.jpg)
Custom XML Attribute <resources> <declare-styleable name="CustomView"> <attr name="label" format="reference|string" /> <attr name="value" format="reference|string" /> <attr name="orientation" format="enum"> <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable> <resources>
![Page 52: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/52.jpg)
Custom XML Attribute <resources> <declare-styleable name="CustomView"> <attr name="label" format="reference|string" /> <attr name="value" format="reference|string" /> <attr name="orientation" format="enum"> <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable> <resources>
![Page 53: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/53.jpg)
Custom XML Attribute <resources> <declare-styleable name="CustomView"> <attr name="label" format="reference|string" /> <attr name="value" format="reference|string" /> <attr name="orientation" format="enum"> <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable> <resources>
![Page 54: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/54.jpg)
Custom XML Attribute <resources> <declare-styleable name="CustomView"> <attr name="label" format="reference|string" /> <attr name="value" format="reference|string" /> <attr name="orientation" format="enum"> <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable> <resources>
![Page 55: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/55.jpg)
Custom XML Attribute <resources> <declare-styleable name="CustomView"> <attr name="label" format="reference|string" /> <attr name="value" format="reference|string" /> <attr name="orientation" format="enum"> <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable> <resources>
![Page 56: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/56.jpg)
Custom XML Attribute <resources> <declare-styleable name="CustomView"> <attr name="label" format="reference|string" /> <attr name="value" format="reference|string" /> <attr name="orientation" format="enum"> <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable> <resources>
![Page 57: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/57.jpg)
1. Add to root XML node xmlns:app="http://schemas.android.com/apk/res-auto" 2. Usage in custom view <de.alosdev.CustomView android:id="@+id/customView" android:layout_width="wrap_content" android:layout_height="wrap_content" app:label="label 1" app:orientation="vertical" app:value="value 1" />
![Page 58: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/58.jpg)
public class CustomView extends LinearLayout { static final int[] ORIENTATION = new int[] { HORIZONTAL, VERTICAL }; public CustomView(Context context, AttributeSet attrs) { super(context, attrs); … TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomView); try { setOrientation(ORIENTATION[ a.getInt(R.styleable.CustomView_orientation, 0)]); } finally { a.recycle(); } } … }
![Page 59: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/59.jpg)
public class CustomView extends LinearLayout { static final int[] ORIENTATION = new int[] { HORIZONTAL, VERTICAL }; public CustomView(Context context, AttributeSet attrs) { super(context, attrs); … TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomView); try { setOrientation(ORIENTATION[ a.getInt(R.styleable.CustomView_orientation, 0)]); } finally { a.recycle(); } } … }
![Page 60: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/60.jpg)
public class CustomView extends LinearLayout { static final int[] ORIENTATION = new int[] { HORIZONTAL, VERTICAL }; public CustomView(Context context, AttributeSet attrs) { super(context, attrs); … TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomView); try { setOrientation(ORIENTATION[ a.getInt(R.styleable.CustomView_orientation, 0)]); } finally { a.recycle(); } } … }
![Page 61: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/61.jpg)
public class CustomView extends LinearLayout { static final int[] ORIENTATION = new int[] { HORIZONTAL, VERTICAL }; public CustomView(Context context, AttributeSet attrs) { super(context, attrs); … TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomView); try { setOrientation(ORIENTATION[ a.getInt(R.styleable.CustomView_orientation, 0)]); } finally { a.recycle(); } } … }
![Page 62: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/62.jpg)
CODE
![Page 63: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/63.jpg)
Custom XML Attribute
![Page 64: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/64.jpg)
Best Practices • You have already an application
» Remove orientation fixation and suppressing of orientation change from manifest to avoid long bug analyzing.
• You start from the scratch » Focus on main classification for faster time
to market » But create an overall concept for better
modularization
![Page 65: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/65.jpg)
Best Practices • If you support both orientations, save
the instance state while orientation changes for more responsiveness » Especially for states, that need a long
computation for creation. » Make the state object Parcelable for
faster write & read and also to have a smaller memory footprint
![Page 66: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/66.jpg)
Developer Hints • You can start an activity for result from
a fragment, so the response can be handled in the fragment.
• If you want to register a special service on every onCreate method of an activity give the ActivityLivecycleCallbacks a try. You can register them in the onCreate method of the application. (min v14)
![Page 67: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/67.jpg)
• If you get a BadParcelableException with the cause ClassNotFound-Exception, the source can be a NullPointerException during the read or write of the Parcelable. Exceptions are hidden during the parcel process.
![Page 68: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/68.jpg)
Listener Hell If you have to many listeners or you think the programming model is old school like the “goto statements”. Give message/ event/ service bus a try. For Android: • Otto from Square • EventBus from greenrobot
See also: Callbacks as our Generations' Go To Statement
![Page 69: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/69.jpg)
Custom Theme & Style Android Ui Utils
![Page 70: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/70.jpg)
ActionBar Style Generator
![Page 71: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/71.jpg)
Holo Color Generator
![Page 72: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/72.jpg)
![Page 73: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/73.jpg)
Q & A
Source: http://www.flickr.com/photos/21496790@N06/5065834411/
![Page 74: MTC 2013 Berlin - Best Practices for Multi Devices](https://reader033.vdocument.in/reader033/viewer/2022042723/5875ee6c1a28ab7d5a8b7b9f/html5/thumbnails/74.jpg)
www.immobilienscout24.de www.immobilienscout24.de
Thanks for your attention & we are hiring! Contact: Hasan Hosgel Twitter: @alosdev Github: alosdev
Best Practices to develop the Layouts for different Android Device Classifications Repo: https://github.com/alosdev/multidevice-nightmare-demo SlideShare: http://www.slideshare.net/hosgel/mtc-2013-berlin-best-practices-for-multi-devices