SlideShare uma empresa Scribd logo
1 de 80
Baixar para ler offline
How to deal with Fragmentation
         on Android
                   Sittiphol Phanvilai
                        Managing Director
                      Hua Lampong Co.,Ltd.
Who am I
• Sittiphol Phanvilai
• nuuneoi
• Cross Platform Mobile
  Application Developer
• Managing Director at
  Hua Lampong Co.,Ltd.
• Founder of DroidSans.com
  the Android Community
• Founder of MOLOME™
MOLOME ™
• Share our experience how
  we beat fragmentation on
  Android

• Who should concern?
  – Designer
  – Developer
Agenda
• Understand the
  fragmentation on Android
• How to beat it
Android
              Freedom


                         Pain for
  Diverse               developer



Happiness
 for User
Android Fragmentation

               “
 Android Fragmentation will be
the huge problem for developer
               ”
      Sittiphol Phanvilai, 2010
“
Problem comes with solution
           or …
            ”
How to deal with Fragmentation on Android
How to deal with Fragmentation on Android
Understand the Fragmentation
• Fragmentation
   – No standard
   – Too many standard
• Fragmentation in Android
  – Software
  – Hardware
Android Fragmentation
• Software




                              And each version of Android
                              has more than 30 generations
                              of ROM

                    4.1
                Jelly Beans
Software Fragmentation
• Each Android OS version has 30+ version of
  ROMs
• Some non-Android phone also has custom
  ROM
API Level
• API Level 1-16
• Some “must-have”
  API is available only
  on high API Level
Android Fragmentation
• Hardware
  – Screen resolution
  – CPU
  – GPU
  – Camera
  – Sensors
Screen Fragmentation
Screen Density       Screen Size
 • ldpi               • Small screen
 • mdpi               • Normal screen
 • hdpi               • Large screen
 • xhdpi              • Extra Large screen
 • tvdpi !
Screen Fragmentation




   … and many more …
CPU Fragmentation
• Android compatible CPU architectures
  – armeabi
  – armeabi-v7a
  – x86
• This causes some application couldn’t run on
  some devices
GPU Fragmentation
• GPU used on Android
  – NVIDIA
  – PowerVR
  – Mali
  – Adreno
  – etc.
• This causes some game couldn’t run properly
  in many devices
Android Fragmentation Visualized




    http://www.techanalyzer.net/2012/08/22/why-android-fragmentation-never-really-mattered/
How to deal with Fragmentation on Android
Learning Curve
• It is very easy to develop easy application
Learning Curve
• But it needs very high effort to make the good
  one
Learning Curve
How to deal with Fragmentation on Android
How to deal with Fragmentation on Android
That's why …
• That’s why
  – There are a lot of junk apps on Google Play
  – UI of Android Application is not so beautiful (in
    average)
How to deal with Fragmentation on Android
How to deal with Fragmentation on Android
How to deal with Fragmentation on Android
Deal with Software Fragmentation




               Build application based on Android 2.2 Froyo
               No need to support Android 2.1 Eclair
API Level
• FACT: You could compile with higher API level
  and run in lower OS version



                 <uses-sdk
                    android:minSdkVersion="8"
                    android:targetSdkVersion="14" />
How to run new API on old OS
• Sorry you couldn’t but you could do the trick

     if (android.os.Build.VERSION.SDK_INT > 8)
     {
           camera = Camera.open(camera_id);
     }
     else
     {
           camera = Camera.open();
     }
Deal with Screen Fragmentation




320x480   540x960   720x1280   600x1024   800x1280
Deal with Screen Fragmentation




               Recommended lowest supported screen:
               normal-mdpi
               Care a bit for lower but no need
               Hard-hearted you need to be
Multiple drawable
• Android provides mechanic to
  use different resource for
  different dpi / screen size
• I suggest you to go for
  drawable-hdpi only, others
  will be scaled automatically
• As same as layout
• Unless you have to
Designing Step
• Always snap each component to screen or
  another component
• Use
  – LinearLayout
  – RelativeLayout
  – FrameLayout
• Don’t fix the position
Snap Component to Screen
Snap to Top of Screen              Snap to the right

Snap to the left




Snap to the left




Snap to Bottom of Screen
Snap Component to Screen
Snap Component
            RelativeLayout
Snap Component

            ListView
Snap Component

            LinearLayout
            - Horizontal
            - weight 1:60:1:60:1:60:1
Snap Component


FrameLayout
Never trust in “Pixel”
• Actual Pixel on Screen
  – px    Don’t use it!

• Physical Size of the Screen
  – dp, dip (Relative to 160dpi)   Recommended for UI

  – sp Recommended for font
  – pt (1/72 inch)
  – in
  – mm
Different dpi Screen Handling
• Unhandled (px)




• Handled (dp)
Designing Step: Component Size
Fixed dp                        Screen Width-Related px
  – Use for the “Exact Size”      – To make the design fit
    component for example           any screen
    button (since your Finger     – To please designer
    is always in the same
    size)
  – This will make final
    product different from
    design
  – To please developer
Example
Fixed dp
Fixed dp
How to deal with Fragmentation on Android
What's actually is in px?
Screen Width-Related px
Screen Width-Related px
• Inherit View or Layout and set the size on
  initializing
• Override onLayout if you wish to manage the
  children’s position manually
• Don’t override onMeasure if not neccessary
Screen Width-Related px

WindowManager wm =
       (WindowManager)getApplicationContext()
       .getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width = display.getWidth();


View v = (View)findViewById(R.id.view);
v.getLayoutParams().width = screenWidth / 3;
Screen Width-Related px
Screen Width-Related px
Screen Height-Related px
• Do it for landscape application
  – Horizontal Scrolling
Considering
• How to consider which one to be used?
  – Purpose of that component
  – Beautifulness
  – Emotional (           )
Example
Example
Common Problem with ImageView
               How to show this image
               fitting the screen in
               aspect ratio?
Common Problem with ImageView
            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/img"
                />
Common Problem with ImageView
            // Inherits ImageView
            protected void onMeasure(int widthMeasureSpec,
                                     int heightMeasureSpec) {
            if (getDrawable() == null)
            {
                 setMeasuredDimension(0, 0);
                 return;
            }
            int width = MeasureSpec.getSize(widthMeasureSpec);
            setMeasuredDimension(width, width *
                getDrawable().getIntrinsicHeight() /
                getDrawable().getIntrinsicWidth());
            }

            // xml
            <com.hlpth.fragmentation.AspectRatioImageView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/img"
                />
More Common Problem
• Please note that you will see this kind of
  problem a lot on Android Application
  Development
• You need to check one by one unavoidably
Deal with CPU Fragmentation
• Directly effect Native Code (NDK)
• Don’t use any platform-specific code or
  assembly code
• Compile for every single CPU architecture

     // Application.mk
     APP_ABI := armeabi armeabi-v7a x86
     APP_PLATFORM := android-9
Fragmentation Beaten
• Congratulations !
How to deal with Fragmentation on Android
RAM
• Each phone has different amount of free RAM
• Always use AdapterView. It will help you
  reduce memory consumption
  – ListView
  – Gallery
  – GridView
Memory Leak
• First reason of app crashing in large-scale
  application
• Don’t 100% trust in Garbage Collector
• Use Context wisely, it holds all of UI
  component inside. If there is still some
  variable point to context, say hello to memory
  leak
• Use Heap monitoring tools comes with ADT
  plugin. Your life will be easier.
Bitmap.recycle()
• If you fully take control the Bitmap object,
  don’t forget to recycle() it when you don’t
  need it anymore.
• Not necessary, just recommended
Nested Layout
• Don’t implement more than 6 levels of nested
  Layout
• There is always the way to reduce level of
  nested Layout. Just need to put more effort.
• LayoutInflater and <merge> is one of the key
  to implement complicated UI with high
  performance
Caching
• Normally there is so limited amount of
  Storage
• But some has so many
• If you wish to cache anything, limit cache size
  to 2-4 MB
OpenGL
• OpenGL could limit number of target devices,
  don’t use it unless you have to.
• Better use OpenGL 1.1 over OpenGL 2.0
Service
• If you need to do some background task, go
  for Service
• Launch when needed only and terminate once
  the task has finished
Multiple APK
• Google Play Store provides feature to use
  multiple apk
• Don’t use it. It will ruin your life in long run.
Target Devices
• You can’t please everybody. If you have to
  scope down the number of target devices, do
  it with hard-hearted.
• To make your application fully compatible with
  3000 THB phone might costs your time double
Custom ROM
• Don’t care a lot about phone with Custom
  ROM. There is always a problem.
• Care only major Custom ROM.
Message to Designer
• Don’t expect what you design and the final
  product will be 100% exactly
• You could expect that on iOS but not on
  Android
• Designer DO need to know Android’s UI
  guideline before design or it might not be able
  to implement
Message to Developer



   Good luck
How to deal with Fragmentation on Android
How to deal with Fragmentation on Android

Mais conteúdo relacionado

Destaque

What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]Sittiphol Phanvilai
 
The web you were used to is gone. Architecture and strategy for your content.
The web you were used to is gone. Architecture and strategy for your content.The web you were used to is gone. Architecture and strategy for your content.
The web you were used to is gone. Architecture and strategy for your content.Alberta Soranzo
 
What's So Special About Mobile?
What's So Special About Mobile?What's So Special About Mobile?
What's So Special About Mobile?Sara Quinn
 
Growth Hacking, Disrupt the Business with Mobile!
Growth Hacking, Disrupt the Business with Mobile! Growth Hacking, Disrupt the Business with Mobile!
Growth Hacking, Disrupt the Business with Mobile! TheFamily
 
5 Lessons in Digital Publishing
5 Lessons in Digital Publishing 5 Lessons in Digital Publishing
5 Lessons in Digital Publishing Mag+
 
Fragmentation in mobile design: fact or fiction
Fragmentation in mobile design: fact or fictionFragmentation in mobile design: fact or fiction
Fragmentation in mobile design: fact or fictionBelen Barros Pena
 
Day in the life of a mobile commerce user
Day in the life of a mobile commerce userDay in the life of a mobile commerce user
Day in the life of a mobile commerce userOn Device Research
 
SEO for Mobile Apps
SEO for Mobile AppsSEO for Mobile Apps
SEO for Mobile AppsAbdul Malick
 
Mobile Marketing Stats Automotive Dealers Should Know
Mobile Marketing Stats Automotive Dealers Should KnowMobile Marketing Stats Automotive Dealers Should Know
Mobile Marketing Stats Automotive Dealers Should Knowcreativeeyeball
 
Mobile Marketing Association - Mobile et tablettes 2nd écran de la TV
Mobile Marketing Association - Mobile et tablettes 2nd écran de la TVMobile Marketing Association - Mobile et tablettes 2nd écran de la TV
Mobile Marketing Association - Mobile et tablettes 2nd écran de la TVPascal Dasseux
 
Awesome android apps
Awesome android appsAwesome android apps
Awesome android appsRichard Byrne
 
Content marketing world_mobile and tablet content distribution_8_17_2012
Content marketing world_mobile and tablet content distribution_8_17_2012Content marketing world_mobile and tablet content distribution_8_17_2012
Content marketing world_mobile and tablet content distribution_8_17_2012interlinkONE
 
Marketing des applications mobiles
Marketing des applications mobilesMarketing des applications mobiles
Marketing des applications mobilesSamir Bellik
 
Mobile Marketing Trend Report - AUG 2012
Mobile Marketing Trend Report - AUG 2012Mobile Marketing Trend Report - AUG 2012
Mobile Marketing Trend Report - AUG 2012Daniel Wood
 
Sneak Peek at Google I/O 2014 Highlights
Sneak Peek at Google I/O 2014 HighlightsSneak Peek at Google I/O 2014 Highlights
Sneak Peek at Google I/O 2014 HighlightsTechAhead
 
I've got 10 million songs in my pocket. Now what?
I've got 10 million songs in my pocket. Now what? I've got 10 million songs in my pocket. Now what?
I've got 10 million songs in my pocket. Now what? Paul Lamere
 
Digiday and Yahoo! Present: Mobile Daily Habits, Moving Marketers Forward
Digiday and  Yahoo! Present: Mobile Daily Habits, Moving Marketers ForwardDigiday and  Yahoo! Present: Mobile Daily Habits, Moving Marketers Forward
Digiday and Yahoo! Present: Mobile Daily Habits, Moving Marketers ForwardDigiday
 

Destaque (20)

What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]
 
The web you were used to is gone. Architecture and strategy for your content.
The web you were used to is gone. Architecture and strategy for your content.The web you were used to is gone. Architecture and strategy for your content.
The web you were used to is gone. Architecture and strategy for your content.
 
What's So Special About Mobile?
What's So Special About Mobile?What's So Special About Mobile?
What's So Special About Mobile?
 
Growth Hacking, Disrupt the Business with Mobile!
Growth Hacking, Disrupt the Business with Mobile! Growth Hacking, Disrupt the Business with Mobile!
Growth Hacking, Disrupt the Business with Mobile!
 
60 apps in 60 mins
60 apps in 60 mins60 apps in 60 mins
60 apps in 60 mins
 
5 Lessons in Digital Publishing
5 Lessons in Digital Publishing 5 Lessons in Digital Publishing
5 Lessons in Digital Publishing
 
Fragmentation in mobile design: fact or fiction
Fragmentation in mobile design: fact or fictionFragmentation in mobile design: fact or fiction
Fragmentation in mobile design: fact or fiction
 
Day in the life of a mobile commerce user
Day in the life of a mobile commerce userDay in the life of a mobile commerce user
Day in the life of a mobile commerce user
 
Keynotes Le Mobile 2013
Keynotes Le Mobile 2013Keynotes Le Mobile 2013
Keynotes Le Mobile 2013
 
SEO for Mobile Apps
SEO for Mobile AppsSEO for Mobile Apps
SEO for Mobile Apps
 
Mobile Marketing Stats Automotive Dealers Should Know
Mobile Marketing Stats Automotive Dealers Should KnowMobile Marketing Stats Automotive Dealers Should Know
Mobile Marketing Stats Automotive Dealers Should Know
 
Mobile Marketing Association - Mobile et tablettes 2nd écran de la TV
Mobile Marketing Association - Mobile et tablettes 2nd écran de la TVMobile Marketing Association - Mobile et tablettes 2nd écran de la TV
Mobile Marketing Association - Mobile et tablettes 2nd écran de la TV
 
Awesome android apps
Awesome android appsAwesome android apps
Awesome android apps
 
Content marketing world_mobile and tablet content distribution_8_17_2012
Content marketing world_mobile and tablet content distribution_8_17_2012Content marketing world_mobile and tablet content distribution_8_17_2012
Content marketing world_mobile and tablet content distribution_8_17_2012
 
Marketing des applications mobiles
Marketing des applications mobilesMarketing des applications mobiles
Marketing des applications mobiles
 
Mobile Marketing Trend Report - AUG 2012
Mobile Marketing Trend Report - AUG 2012Mobile Marketing Trend Report - AUG 2012
Mobile Marketing Trend Report - AUG 2012
 
Sneak Peek at Google I/O 2014 Highlights
Sneak Peek at Google I/O 2014 HighlightsSneak Peek at Google I/O 2014 Highlights
Sneak Peek at Google I/O 2014 Highlights
 
Create great UIs for budget phones
Create great UIs for budget phonesCreate great UIs for budget phones
Create great UIs for budget phones
 
I've got 10 million songs in my pocket. Now what?
I've got 10 million songs in my pocket. Now what? I've got 10 million songs in my pocket. Now what?
I've got 10 million songs in my pocket. Now what?
 
Digiday and Yahoo! Present: Mobile Daily Habits, Moving Marketers Forward
Digiday and  Yahoo! Present: Mobile Daily Habits, Moving Marketers ForwardDigiday and  Yahoo! Present: Mobile Daily Habits, Moving Marketers Forward
Digiday and Yahoo! Present: Mobile Daily Habits, Moving Marketers Forward
 

Semelhante a How to deal with Fragmentation on Android

Android training day 3
Android training day 3Android training day 3
Android training day 3Vivek Bhusal
 
Introduction to mobile programming with Androids.
Introduction to mobile programming with Androids. Introduction to mobile programming with Androids.
Introduction to mobile programming with Androids. Maksim Golivkin
 
Phonegap - An Introduction
Phonegap - An IntroductionPhonegap - An Introduction
Phonegap - An IntroductionTyler Johnston
 
Android webinar class_1
Android webinar class_1Android webinar class_1
Android webinar class_1Edureka!
 
Android Programming Basic
Android Programming BasicAndroid Programming Basic
Android Programming BasicDuy Do Phan
 
Creating apps that work on all screen sizes
Creating apps that work on all screen sizesCreating apps that work on all screen sizes
Creating apps that work on all screen sizesRavi Vyas
 
Supporting Multiple Screen In Android
Supporting Multiple Screen In AndroidSupporting Multiple Screen In Android
Supporting Multiple Screen In Androidrobbypontas
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignJulia Vi
 
Сергей Жук "Android Performance Tips & Tricks"
Сергей Жук "Android Performance Tips & Tricks"Сергей Жук "Android Performance Tips & Tricks"
Сергей Жук "Android Performance Tips & Tricks"Fwdays
 
Android Performance Tips & Tricks
Android Performance Tips & TricksAndroid Performance Tips & Tricks
Android Performance Tips & TricksSergii Zhuk
 
Designing Android apps for multiple screens
Designing Android apps for multiple screensDesigning Android apps for multiple screens
Designing Android apps for multiple screensAbhijeet Dutta
 
Christian Kurzke; Getting Your Content on the Big Screen
Christian Kurzke; Getting Your Content on the Big ScreenChristian Kurzke; Getting Your Content on the Big Screen
Christian Kurzke; Getting Your Content on the Big ScreenDroidcon Berlin
 
Dreamweaver CS6, jQuery, PhoneGap, mobile design
Dreamweaver CS6, jQuery, PhoneGap, mobile designDreamweaver CS6, jQuery, PhoneGap, mobile design
Dreamweaver CS6, jQuery, PhoneGap, mobile designDee Sadler
 
responsive awareness
responsive awarenessresponsive awareness
responsive awarenessonehundred_be
 
Coding for different resolutions
Coding for different resolutionsCoding for different resolutions
Coding for different resolutionsRobin Srivastava
 
Supporting multiple screens on android
Supporting multiple screens on androidSupporting multiple screens on android
Supporting multiple screens on androidLi SUN
 
Design guidelines for android developers
Design guidelines for android developersDesign guidelines for android developers
Design guidelines for android developersQandil Tariq
 
"WebView, the fifth element" por @fernando_cejas
"WebView, the fifth element" por @fernando_cejas"WebView, the fifth element" por @fernando_cejas
"WebView, the fifth element" por @fernando_cejaswebcat
 

Semelhante a How to deal with Fragmentation on Android (20)

Android training day 3
Android training day 3Android training day 3
Android training day 3
 
Introduction to mobile programming with Androids.
Introduction to mobile programming with Androids. Introduction to mobile programming with Androids.
Introduction to mobile programming with Androids.
 
Phonegap - An Introduction
Phonegap - An IntroductionPhonegap - An Introduction
Phonegap - An Introduction
 
Android webinar class_1
Android webinar class_1Android webinar class_1
Android webinar class_1
 
Android Programming Basic
Android Programming BasicAndroid Programming Basic
Android Programming Basic
 
React Native on Android TV
React Native on Android TVReact Native on Android TV
React Native on Android TV
 
Creating apps that work on all screen sizes
Creating apps that work on all screen sizesCreating apps that work on all screen sizes
Creating apps that work on all screen sizes
 
Supporting Multiple Screen In Android
Supporting Multiple Screen In AndroidSupporting Multiple Screen In Android
Supporting Multiple Screen In Android
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Сергей Жук "Android Performance Tips & Tricks"
Сергей Жук "Android Performance Tips & Tricks"Сергей Жук "Android Performance Tips & Tricks"
Сергей Жук "Android Performance Tips & Tricks"
 
Android Performance Tips & Tricks
Android Performance Tips & TricksAndroid Performance Tips & Tricks
Android Performance Tips & Tricks
 
Designing Android apps for multiple screens
Designing Android apps for multiple screensDesigning Android apps for multiple screens
Designing Android apps for multiple screens
 
UI and UX for Mobile Developers
UI and UX for Mobile DevelopersUI and UX for Mobile Developers
UI and UX for Mobile Developers
 
Christian Kurzke; Getting Your Content on the Big Screen
Christian Kurzke; Getting Your Content on the Big ScreenChristian Kurzke; Getting Your Content on the Big Screen
Christian Kurzke; Getting Your Content on the Big Screen
 
Dreamweaver CS6, jQuery, PhoneGap, mobile design
Dreamweaver CS6, jQuery, PhoneGap, mobile designDreamweaver CS6, jQuery, PhoneGap, mobile design
Dreamweaver CS6, jQuery, PhoneGap, mobile design
 
responsive awareness
responsive awarenessresponsive awareness
responsive awareness
 
Coding for different resolutions
Coding for different resolutionsCoding for different resolutions
Coding for different resolutions
 
Supporting multiple screens on android
Supporting multiple screens on androidSupporting multiple screens on android
Supporting multiple screens on android
 
Design guidelines for android developers
Design guidelines for android developersDesign guidelines for android developers
Design guidelines for android developers
 
"WebView, the fifth element" por @fernando_cejas
"WebView, the fifth element" por @fernando_cejas"WebView, the fifth element" por @fernando_cejas
"WebView, the fifth element" por @fernando_cejas
 

Mais de Sittiphol Phanvilai

Smart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSittiphol Phanvilai
 
Firebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteFirebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteSittiphol Phanvilai
 
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]Sittiphol Phanvilai
 
I/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidI/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidSittiphol Phanvilai
 
I/O Rewind 2015 : Android Design Support Library
I/O Rewind 2015 : Android Design Support LibraryI/O Rewind 2015 : Android Design Support Library
I/O Rewind 2015 : Android Design Support LibrarySittiphol Phanvilai
 
The way Tech World is heading to and how to survive in this fast moving world
The way Tech World is heading to and how to survive in this fast moving worldThe way Tech World is heading to and how to survive in this fast moving world
The way Tech World is heading to and how to survive in this fast moving worldSittiphol Phanvilai
 
Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Mobile Dev Talk #0 Keynote & Mobile Trend 2015Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Mobile Dev Talk #0 Keynote & Mobile Trend 2015Sittiphol Phanvilai
 
Mobile Market : Past Present Now and Then
Mobile Market : Past Present Now and ThenMobile Market : Past Present Now and Then
Mobile Market : Past Present Now and ThenSittiphol Phanvilai
 
GTUG Bangkok 2011 Android Ecosystem Session
GTUG Bangkok 2011 Android Ecosystem SessionGTUG Bangkok 2011 Android Ecosystem Session
GTUG Bangkok 2011 Android Ecosystem SessionSittiphol Phanvilai
 

Mais de Sittiphol Phanvilai (10)

Smart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathon
 
Firebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteFirebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: Keynote
 
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
 
I/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidI/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in Android
 
I/O Rewind 2015 : Android Design Support Library
I/O Rewind 2015 : Android Design Support LibraryI/O Rewind 2015 : Android Design Support Library
I/O Rewind 2015 : Android Design Support Library
 
The way Tech World is heading to and how to survive in this fast moving world
The way Tech World is heading to and how to survive in this fast moving worldThe way Tech World is heading to and how to survive in this fast moving world
The way Tech World is heading to and how to survive in this fast moving world
 
Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Mobile Dev Talk #0 Keynote & Mobile Trend 2015Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Mobile Dev Talk #0 Keynote & Mobile Trend 2015
 
Tech World 2015
Tech World 2015Tech World 2015
Tech World 2015
 
Mobile Market : Past Present Now and Then
Mobile Market : Past Present Now and ThenMobile Market : Past Present Now and Then
Mobile Market : Past Present Now and Then
 
GTUG Bangkok 2011 Android Ecosystem Session
GTUG Bangkok 2011 Android Ecosystem SessionGTUG Bangkok 2011 Android Ecosystem Session
GTUG Bangkok 2011 Android Ecosystem Session
 

How to deal with Fragmentation on Android

  • 1. How to deal with Fragmentation on Android Sittiphol Phanvilai Managing Director Hua Lampong Co.,Ltd.
  • 2. Who am I • Sittiphol Phanvilai • nuuneoi • Cross Platform Mobile Application Developer • Managing Director at Hua Lampong Co.,Ltd. • Founder of DroidSans.com the Android Community • Founder of MOLOME™
  • 3. MOLOME ™ • Share our experience how we beat fragmentation on Android • Who should concern? – Designer – Developer
  • 4. Agenda • Understand the fragmentation on Android • How to beat it
  • 5. Android Freedom Pain for Diverse developer Happiness for User
  • 6. Android Fragmentation “ Android Fragmentation will be the huge problem for developer ” Sittiphol Phanvilai, 2010
  • 7. “ Problem comes with solution or … ”
  • 10. Understand the Fragmentation • Fragmentation – No standard – Too many standard • Fragmentation in Android – Software – Hardware
  • 11. Android Fragmentation • Software And each version of Android has more than 30 generations of ROM 4.1 Jelly Beans
  • 12. Software Fragmentation • Each Android OS version has 30+ version of ROMs • Some non-Android phone also has custom ROM
  • 13. API Level • API Level 1-16 • Some “must-have” API is available only on high API Level
  • 14. Android Fragmentation • Hardware – Screen resolution – CPU – GPU – Camera – Sensors
  • 15. Screen Fragmentation Screen Density Screen Size • ldpi • Small screen • mdpi • Normal screen • hdpi • Large screen • xhdpi • Extra Large screen • tvdpi !
  • 16. Screen Fragmentation … and many more …
  • 17. CPU Fragmentation • Android compatible CPU architectures – armeabi – armeabi-v7a – x86 • This causes some application couldn’t run on some devices
  • 18. GPU Fragmentation • GPU used on Android – NVIDIA – PowerVR – Mali – Adreno – etc. • This causes some game couldn’t run properly in many devices
  • 19. Android Fragmentation Visualized http://www.techanalyzer.net/2012/08/22/why-android-fragmentation-never-really-mattered/
  • 21. Learning Curve • It is very easy to develop easy application
  • 22. Learning Curve • But it needs very high effort to make the good one
  • 26. That's why … • That’s why – There are a lot of junk apps on Google Play – UI of Android Application is not so beautiful (in average)
  • 30. Deal with Software Fragmentation Build application based on Android 2.2 Froyo No need to support Android 2.1 Eclair
  • 31. API Level • FACT: You could compile with higher API level and run in lower OS version <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14" />
  • 32. How to run new API on old OS • Sorry you couldn’t but you could do the trick if (android.os.Build.VERSION.SDK_INT > 8) { camera = Camera.open(camera_id); } else { camera = Camera.open(); }
  • 33. Deal with Screen Fragmentation 320x480 540x960 720x1280 600x1024 800x1280
  • 34. Deal with Screen Fragmentation Recommended lowest supported screen: normal-mdpi Care a bit for lower but no need Hard-hearted you need to be
  • 35. Multiple drawable • Android provides mechanic to use different resource for different dpi / screen size • I suggest you to go for drawable-hdpi only, others will be scaled automatically • As same as layout • Unless you have to
  • 36. Designing Step • Always snap each component to screen or another component • Use – LinearLayout – RelativeLayout – FrameLayout • Don’t fix the position
  • 37. Snap Component to Screen Snap to Top of Screen Snap to the right Snap to the left Snap to the left Snap to Bottom of Screen
  • 39. Snap Component RelativeLayout
  • 40. Snap Component ListView
  • 41. Snap Component LinearLayout - Horizontal - weight 1:60:1:60:1:60:1
  • 43. Never trust in “Pixel” • Actual Pixel on Screen – px Don’t use it! • Physical Size of the Screen – dp, dip (Relative to 160dpi) Recommended for UI – sp Recommended for font – pt (1/72 inch) – in – mm
  • 44. Different dpi Screen Handling • Unhandled (px) • Handled (dp)
  • 45. Designing Step: Component Size Fixed dp Screen Width-Related px – Use for the “Exact Size” – To make the design fit component for example any screen button (since your Finger – To please designer is always in the same size) – This will make final product different from design – To please developer
  • 52. Screen Width-Related px • Inherit View or Layout and set the size on initializing • Override onLayout if you wish to manage the children’s position manually • Don’t override onMeasure if not neccessary
  • 53. Screen Width-Related px WindowManager wm = (WindowManager)getApplicationContext() .getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int width = display.getWidth(); View v = (View)findViewById(R.id.view); v.getLayoutParams().width = screenWidth / 3;
  • 56. Screen Height-Related px • Do it for landscape application – Horizontal Scrolling
  • 57. Considering • How to consider which one to be used? – Purpose of that component – Beautifulness – Emotional ( )
  • 60. Common Problem with ImageView How to show this image fitting the screen in aspect ratio?
  • 61. Common Problem with ImageView <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="centerCrop" android:src="@drawable/img" />
  • 62. Common Problem with ImageView // Inherits ImageView protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (getDrawable() == null) { setMeasuredDimension(0, 0); return; } int width = MeasureSpec.getSize(widthMeasureSpec); setMeasuredDimension(width, width * getDrawable().getIntrinsicHeight() / getDrawable().getIntrinsicWidth()); } // xml <com.hlpth.fragmentation.AspectRatioImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="centerCrop" android:src="@drawable/img" />
  • 63. More Common Problem • Please note that you will see this kind of problem a lot on Android Application Development • You need to check one by one unavoidably
  • 64. Deal with CPU Fragmentation • Directly effect Native Code (NDK) • Don’t use any platform-specific code or assembly code • Compile for every single CPU architecture // Application.mk APP_ABI := armeabi armeabi-v7a x86 APP_PLATFORM := android-9
  • 67. RAM • Each phone has different amount of free RAM • Always use AdapterView. It will help you reduce memory consumption – ListView – Gallery – GridView
  • 68. Memory Leak • First reason of app crashing in large-scale application • Don’t 100% trust in Garbage Collector • Use Context wisely, it holds all of UI component inside. If there is still some variable point to context, say hello to memory leak • Use Heap monitoring tools comes with ADT plugin. Your life will be easier.
  • 69. Bitmap.recycle() • If you fully take control the Bitmap object, don’t forget to recycle() it when you don’t need it anymore. • Not necessary, just recommended
  • 70. Nested Layout • Don’t implement more than 6 levels of nested Layout • There is always the way to reduce level of nested Layout. Just need to put more effort. • LayoutInflater and <merge> is one of the key to implement complicated UI with high performance
  • 71. Caching • Normally there is so limited amount of Storage • But some has so many • If you wish to cache anything, limit cache size to 2-4 MB
  • 72. OpenGL • OpenGL could limit number of target devices, don’t use it unless you have to. • Better use OpenGL 1.1 over OpenGL 2.0
  • 73. Service • If you need to do some background task, go for Service • Launch when needed only and terminate once the task has finished
  • 74. Multiple APK • Google Play Store provides feature to use multiple apk • Don’t use it. It will ruin your life in long run.
  • 75. Target Devices • You can’t please everybody. If you have to scope down the number of target devices, do it with hard-hearted. • To make your application fully compatible with 3000 THB phone might costs your time double
  • 76. Custom ROM • Don’t care a lot about phone with Custom ROM. There is always a problem. • Care only major Custom ROM.
  • 77. Message to Designer • Don’t expect what you design and the final product will be 100% exactly • You could expect that on iOS but not on Android • Designer DO need to know Android’s UI guideline before design or it might not be able to implement
  • 78. Message to Developer Good luck