SlideShare a Scribd company logo
1 of 24
Download to read offline
AnDevCon III

                     Backwards
                   Compatibility:
                   Strategies and
                       Tactics
Copyright © 2012 CommonsWare, LLC
Device Mix




                        image Copyright © 2012 Google, Inc. – reprinted with permission




Copyright © 2012 CommonsWare, LLC
Device Mix
    ●   The Market Is Not the World
         ●   Kindle Fire
         ●   NOOK Tablet
         ●   Wearables (WIMM, I'm Watch, etc.)
         ●   Miscellaneous non-Market devices
    ●   If You Distribute to These, Take Their Versions Into
        Account!



Copyright © 2012 CommonsWare, LLC
Device Mix
    ●   Predictions Sure To Go Wrong
         ●   November 2012: ICS and newer reaches majority status
               –   New device sales
               –   Upgrades for existing devices
         ●   December 2012: Mayan Apocalypse
         ●   April 2013: Android 2.x below 20%
         ●   September 2013: Android 2.x below 5%
         ●   December 2013: Ragnarök


Copyright © 2012 CommonsWare, LLC
Competing Strategies
    ●   Old API-Centric
         ●   Lowest common denominator
         ●   Today: Android 2.3, maybe 2.2
         ●   Only deal with newer things when unavoidable
    ●   New API-Centric
         ●   More aggressively support newer capabilities
              –   Particularly with respect to UI
         ●   Today: ICS
         ●   Gracefully degrade for older devices

Copyright © 2012 CommonsWare, LLC
Forwards, Not Backwards
    ●   Older Ain't Gettin' Any Bigger
         ●   Aim for the increasing market share, not the decreasing
             share
    ●   Sneezers' Devices
         ●   Bloggers, media, etc.
         ●   Tend towards newer devices
         ●   If you look stale, may impact their interest in you



Copyright © 2012 CommonsWare, LLC
Forwards, Not Backwards
    ●   Distinctive, Not Decomposing
         ●   Are there new features that can give you a competitive
             edge?
               –   Even if not all the users can take advantage of them
    ●   It's the Way the (Web) World Works
         ●   IE6-only versus graceful degradation
         ●   Well-trod path, needing Android-specific tactics




Copyright © 2012 CommonsWare, LLC
Targets and Strategies
    ●   Old API-Centric
         ●   Build target = min SDK version = lowest common
             denominator
         ●   Target SDK version no higher than min SDK version
    ●   New API-Centric
         ●   Build target = oldest version that has everything you are
             using directly (or via library)
         ●   Min SDK version = oldest you are supporting
         ●   Target SDK version = current-ish Android version
Copyright © 2012 CommonsWare, LLC
Validating Compatibility
    ●   Compile-Time: Lint
         ●   Keep your Android SDK tools/ADT updated!
         ●   Will warn you when you try using newer stuff on older
             minSdkVersion
               –   Requires manual lint run from Eclipse menu
         ●   Use annotations to suppress warnings
               –   @TargetApi(NN)




Copyright © 2012 CommonsWare, LLC
Validating Compatibility
    ●   Testing
         ●   Directly via emulator
         ●   Directly via available hardware
         ●   Bulk-testing Services
               –   TestDroid Cloud
               –   LessPainful
               –   Apkudo
               –   Etc.



Copyright © 2012 CommonsWare, LLC
Libraries for Compatibility
    ●   Android Support Package
         ●   Fragments
              –   Large subset, but not everything from native API Level 11+
         ●   Loaders
         ●   GridLayout
         ●   *Compat Classes
              –   Access to newer constants
              –   Helper methods to get at newer capabilities while gracefully
                  degrading to no-ops/defaults
         ●   Separate Implementations

Copyright © 2012 CommonsWare, LLC
Libraries for Compatibility
    ●   Action Bar Sherlock
         ●   Implementation of ActionBar for Android 2.x
         ●   Same API as native API Level 11+
    ●   Nine Old Androids
         ●   Implementation of android.animation framework
             for Android 1.x/2.x




Copyright © 2012 CommonsWare, LLC
Ad-Hoc Backports
    ●   Find AOSP Code, Clone, Fix
         ●   New widgets (e.g., Switch)
         ●   Other stuff largely separable from firmware
         ●   Challenges
               –   Finding resources
               –   Dealing with package-private methods




Copyright © 2012 CommonsWare, LLC
Library/Backport Strategy
    ●   Use as Temporary Scaffolding
         ●   Know which API levels a given library or backport is
             addressing
         ●   May vary by what you are using
    ●   Remove In Time
         ●   Once you no longer are supporting the older API levels,
             drop the scaffold and re-test




Copyright © 2012 CommonsWare, LLC
Java Version Guards
    ●   Android 2.x+
         ●   Wrap any references to items from newer API level in a
             test of the API level

 if (Build.VERSION.SDK_INT>Build.VERSION_CODES.GINGERBREAD) {
     // do something
 }




Copyright © 2012 CommonsWare, LLC
Java Version Guards
    ●   Android 2.x+
         ●   Wrap any references to items from newer API level in a
             test of the API level

 if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.GINGERBREAD) {
     @TargetApi(11)
     // do something needing API Level 11+
 }




Copyright © 2012 CommonsWare, LLC
Java Version Guards
    ●   Scenario: AsyncTask
         ●   Serialized if targetSdkVersion >= 14
         ●   Use executeOnExecutor() to force to classic thread
             pool model
         ●   Problem: executeOnExecutor() new to API Level 11
         ●   Solution: version guard block




Copyright © 2012 CommonsWare, LLC
Java Version Guards
    ●   Android 1.x
         ●   Problem: Dalvik complains if you load a class that refers
             to items from a newer API level
         ●   Solution
               –   Isolate newer-API items in a separate helper class
               –   Only refer to that helper class within a version guard block




Copyright © 2012 CommonsWare, LLC
Java Version Guards
    ●   The Old API-Centric Approach
         ●   Use version guard to detect newer API level
         ●   Use reflection to access items that only exist at that API
             level
         ●   Benefit: can leave build target on older API level
               –   Build target only affects what you directly reference




Copyright © 2012 CommonsWare, LLC
Versioned Resources
    ●   Use -vNN Resource Set Suffix
         ●   Apply to resources valid for API Level NN and higher
         ●   Scenario
               –   res/values/ = good for anything
               –   res/values-v11/ = good for Honeycomb and newer
         ●   Example
               –   Style in -v11 that references Theme.Holo
               –   Style with same name in default directory that does not
                   reference Theme.Holo


Copyright © 2012 CommonsWare, LLC
Versioned Components
    ●   Components Valid for Certain API Levels
         ●   Activity only needed on Android 3.1+
         ●   Different app widgets for API Level 11, older devices
    ●   Technique
         ●   Boolean resource, contained in two resource sets
               –   Default plus -vNN set
         ●   Use boolean resource in android:enabled attribute in
             manifest
               –   Disabled components do not show up anywhere

Copyright © 2012 CommonsWare, LLC
Scenario: Preferences
   ●   Goals
        ●   Want to use PreferenceFragments and headers on API
            Level 11 and higher
        ●   Want preferences to still work on Android 2.x
   ●   Option #1: Different PreferenceActivity Classes
        ●   Use versioned components trick to dictate which one is
            available
        ●   Use action, not component, in launching Intent
        ●   Reuse preference XML as best you can


Copyright © 2012 CommonsWare, LLC
Scenario: Preferences
    ●   Option #2: Version Guards
         ●   One PreferenceActivity
         ●   onBuildHeaders() only called on API Level 11+
         ●   Reuse preference XML as best you can
    ●   Option #3: Backport
         ●   Find current implementation (source, resources)
         ●   Convert to use Android Support fragments
         ●   Most difficulty, but consistent implementation,
             look-and-feel
Copyright © 2012 CommonsWare, LLC
QOTD
  “You’re a Web developer in Java” is the first thing I tell every person
  mentioning fragmentation. There are no tablets. There are no
  phones. There’s no Google TV. There is only an unlimited set of
  configurations of every conceivable feature. Write your application
  in a dynamic, progressively enhancing manner that follows well-
  documented patterns and you will be just fine.
                                                            Jake Wharton




Copyright © 2012 CommonsWare, LLC

More Related Content

What's hot

Android Programming Basic
Android Programming BasicAndroid Programming Basic
Android Programming BasicDuy Do Phan
 
Basic android development
Basic android developmentBasic android development
Basic android developmentUpanya Singh
 
9780134433646 annuzzi ch02 (1)
9780134433646 annuzzi ch02 (1)9780134433646 annuzzi ch02 (1)
9780134433646 annuzzi ch02 (1)Peter Mburu
 
Developing and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidDeveloping and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidElvis Jon Freddy Sitinjak
 
Ii 1300-java essentials for android
Ii 1300-java essentials for androidIi 1300-java essentials for android
Ii 1300-java essentials for androidAdrian Mikeliunas
 
Introduction to Android Development Part 1
Introduction to Android Development Part 1Introduction to Android Development Part 1
Introduction to Android Development Part 1Kainda Kiniel Daka
 
Android and its feature
Android and its featureAndroid and its feature
Android and its featureShubham Kumar
 
Ii 1500-publishing your android application
Ii 1500-publishing your android applicationIi 1500-publishing your android application
Ii 1500-publishing your android applicationAdrian Mikeliunas
 
Java Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development WorkshopJava Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development WorkshopKasun Dananjaya Delgolla
 
Ad102 - Extreme Makeover -- LotusScript and Java Editor Edition
Ad102 - Extreme Makeover -- LotusScript and Java Editor EditionAd102 - Extreme Makeover -- LotusScript and Java Editor Edition
Ad102 - Extreme Makeover -- LotusScript and Java Editor Editionddrschiw
 
Rationalize Android Development with StAnD - Clement Escoffier, akquinet
Rationalize Android Development with StAnD - Clement Escoffier, akquinetRationalize Android Development with StAnD - Clement Escoffier, akquinet
Rationalize Android Development with StAnD - Clement Escoffier, akquinetParis Open Source Summit
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentCan Elmas
 
AD201 - IBM Domino Application Development Today And Tomorrow
AD201 - IBM Domino Application Development Today And TomorrowAD201 - IBM Domino Application Development Today And Tomorrow
AD201 - IBM Domino Application Development Today And Tomorrowpjanzen11
 
Android fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersAndroid fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersBoom Shukla
 
MTJ Taking Mobile Java Developers to the Next Level
MTJ Taking Mobile Java Developers to the Next LevelMTJ Taking Mobile Java Developers to the Next Level
MTJ Taking Mobile Java Developers to the Next Levelgustavoeliano
 
Android Development Workshop
Android Development WorkshopAndroid Development Workshop
Android Development WorkshopPeter Robinett
 

What's hot (20)

Android Programming Basic
Android Programming BasicAndroid Programming Basic
Android Programming Basic
 
Basic android development
Basic android developmentBasic android development
Basic android development
 
Android Programming
Android ProgrammingAndroid Programming
Android Programming
 
Android session-1-sajib
Android session-1-sajibAndroid session-1-sajib
Android session-1-sajib
 
9780134433646 annuzzi ch02 (1)
9780134433646 annuzzi ch02 (1)9780134433646 annuzzi ch02 (1)
9780134433646 annuzzi ch02 (1)
 
Developing and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidDeveloping and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-android
 
Mobile Java
Mobile JavaMobile Java
Mobile Java
 
Android
Android Android
Android
 
Ii 1300-java essentials for android
Ii 1300-java essentials for androidIi 1300-java essentials for android
Ii 1300-java essentials for android
 
Introduction to Android Development Part 1
Introduction to Android Development Part 1Introduction to Android Development Part 1
Introduction to Android Development Part 1
 
Android and its feature
Android and its featureAndroid and its feature
Android and its feature
 
Ii 1500-publishing your android application
Ii 1500-publishing your android applicationIi 1500-publishing your android application
Ii 1500-publishing your android application
 
Java Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development WorkshopJava Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development Workshop
 
Ad102 - Extreme Makeover -- LotusScript and Java Editor Edition
Ad102 - Extreme Makeover -- LotusScript and Java Editor EditionAd102 - Extreme Makeover -- LotusScript and Java Editor Edition
Ad102 - Extreme Makeover -- LotusScript and Java Editor Edition
 
Rationalize Android Development with StAnD - Clement Escoffier, akquinet
Rationalize Android Development with StAnD - Clement Escoffier, akquinetRationalize Android Development with StAnD - Clement Escoffier, akquinet
Rationalize Android Development with StAnD - Clement Escoffier, akquinet
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
AD201 - IBM Domino Application Development Today And Tomorrow
AD201 - IBM Domino Application Development Today And TomorrowAD201 - IBM Domino Application Development Today And Tomorrow
AD201 - IBM Domino Application Development Today And Tomorrow
 
Android fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersAndroid fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginners
 
MTJ Taking Mobile Java Developers to the Next Level
MTJ Taking Mobile Java Developers to the Next LevelMTJ Taking Mobile Java Developers to the Next Level
MTJ Taking Mobile Java Developers to the Next Level
 
Android Development Workshop
Android Development WorkshopAndroid Development Workshop
Android Development Workshop
 

Similar to Backwards Compatibility: Strategies and Tactics

Securing User Data with SQLCipher
Securing User Data with SQLCipherSecuring User Data with SQLCipher
Securing User Data with SQLCipherCommonsWare
 
App Integration (Revised and Updated)
App Integration (Revised and Updated)App Integration (Revised and Updated)
App Integration (Revised and Updated)CommonsWare
 
Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsCommonsWare
 
App integration: Strategies and Tactics
App integration: Strategies and TacticsApp integration: Strategies and Tactics
App integration: Strategies and TacticsCommonsWare
 
Android workshop material
Android workshop materialAndroid workshop material
Android workshop materialReza Yogaswara
 
From Android to the Mobile Web
From Android to the Mobile WebFrom Android to the Mobile Web
From Android to the Mobile WebCommonsWare
 
What's New in Jelly Bean
What's New in Jelly BeanWhat's New in Jelly Bean
What's New in Jelly BeanCommonsWare
 
Continuous integration for androids
Continuous integration for androidsContinuous integration for androids
Continuous integration for androidsKirill Zotin
 
Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app developmentAbhishekKumar4779
 
Android studio&Gradle&Autotest
Android studio&Gradle&AutotestAndroid studio&Gradle&Autotest
Android studio&Gradle&Autotest毅 方
 
Android_Studio_Structure.docx
Android_Studio_Structure.docxAndroid_Studio_Structure.docx
Android_Studio_Structure.docxKNANTHINIMCA
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a NutshellAleix Solé
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Javaamaankhan
 

Similar to Backwards Compatibility: Strategies and Tactics (20)

Securing User Data with SQLCipher
Securing User Data with SQLCipherSecuring User Data with SQLCipher
Securing User Data with SQLCipher
 
App Integration (Revised and Updated)
App Integration (Revised and Updated)App Integration (Revised and Updated)
App Integration (Revised and Updated)
 
Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable Projects
 
App integration: Strategies and Tactics
App integration: Strategies and TacticsApp integration: Strategies and Tactics
App integration: Strategies and Tactics
 
Android workshop material
Android workshop materialAndroid workshop material
Android workshop material
 
From Android to the Mobile Web
From Android to the Mobile WebFrom Android to the Mobile Web
From Android to the Mobile Web
 
What's New in Jelly Bean
What's New in Jelly BeanWhat's New in Jelly Bean
What's New in Jelly Bean
 
Gl android platform
Gl android platformGl android platform
Gl android platform
 
Android My Seminar
Android My SeminarAndroid My Seminar
Android My Seminar
 
Continuous integration for androids
Continuous integration for androidsContinuous integration for androids
Continuous integration for androids
 
Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app development
 
Android studio&Gradle&Autotest
Android studio&Gradle&AutotestAndroid studio&Gradle&Autotest
Android studio&Gradle&Autotest
 
Android Attacks
Android AttacksAndroid Attacks
Android Attacks
 
Android Platform Architecture
Android Platform ArchitectureAndroid Platform Architecture
Android Platform Architecture
 
Android_Studio_Structure.docx
Android_Studio_Structure.docxAndroid_Studio_Structure.docx
Android_Studio_Structure.docx
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a Nutshell
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
Android NDK
Android NDKAndroid NDK
Android NDK
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Java
 
Android
AndroidAndroid
Android
 

More from CommonsWare

Getting Android Developers for Your Wearables
Getting Android Developers for Your WearablesGetting Android Developers for Your Wearables
Getting Android Developers for Your WearablesCommonsWare
 
When Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsWhen Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsCommonsWare
 
The Action Bar: Front to Back
The Action Bar: Front to BackThe Action Bar: Front to Back
The Action Bar: Front to BackCommonsWare
 
Android Security: Defending Your Users
Android Security: Defending Your UsersAndroid Security: Defending Your Users
Android Security: Defending Your UsersCommonsWare
 
Secondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerSecondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerCommonsWare
 
Mastering the Master Detail Pattern
Mastering the Master Detail PatternMastering the Master Detail Pattern
Mastering the Master Detail PatternCommonsWare
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful ThreadingCommonsWare
 
Android Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewAndroid Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewCommonsWare
 
Maps V2... And You!
Maps V2... And You!Maps V2... And You!
Maps V2... And You!CommonsWare
 
A Deep Dive Into ViewPager
A Deep Dive Into ViewPagerA Deep Dive Into ViewPager
A Deep Dive Into ViewPagerCommonsWare
 
Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2CommonsWare
 
Integrate Android Apps and Web Apps
Integrate Android Apps and Web AppsIntegrate Android Apps and Web Apps
Integrate Android Apps and Web AppsCommonsWare
 
The Wonderful World of Wearables
The Wonderful World of WearablesThe Wonderful World of Wearables
The Wonderful World of WearablesCommonsWare
 
Beaming Data to Devices with NFC
Beaming Data to Devices with NFCBeaming Data to Devices with NFC
Beaming Data to Devices with NFCCommonsWare
 
Making Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsMaking Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsCommonsWare
 
AppsWorld Keynote
AppsWorld KeynoteAppsWorld Keynote
AppsWorld KeynoteCommonsWare
 
Rich Text Editing and Beyond
Rich Text Editing and BeyondRich Text Editing and Beyond
Rich Text Editing and BeyondCommonsWare
 
Android Hardware That's A Little Bit... Odd
Android Hardware That's A Little Bit... OddAndroid Hardware That's A Little Bit... Odd
Android Hardware That's A Little Bit... OddCommonsWare
 
Google TV For Fun
Google TV For FunGoogle TV For Fun
Google TV For FunCommonsWare
 

More from CommonsWare (20)

Getting Android Developers for Your Wearables
Getting Android Developers for Your WearablesGetting Android Developers for Your Wearables
Getting Android Developers for Your Wearables
 
When Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsWhen Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable Apps
 
The Action Bar: Front to Back
The Action Bar: Front to BackThe Action Bar: Front to Back
The Action Bar: Front to Back
 
Android Security: Defending Your Users
Android Security: Defending Your UsersAndroid Security: Defending Your Users
Android Security: Defending Your Users
 
Secondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerSecondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManager
 
Mastering the Master Detail Pattern
Mastering the Master Detail PatternMastering the Master Detail Pattern
Mastering the Master Detail Pattern
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful Threading
 
Android Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewAndroid Development: The 20,000-Foot View
Android Development: The 20,000-Foot View
 
Maps V2... And You!
Maps V2... And You!Maps V2... And You!
Maps V2... And You!
 
A Deep Dive Into ViewPager
A Deep Dive Into ViewPagerA Deep Dive Into ViewPager
A Deep Dive Into ViewPager
 
Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2
 
Integrate Android Apps and Web Apps
Integrate Android Apps and Web AppsIntegrate Android Apps and Web Apps
Integrate Android Apps and Web Apps
 
X Means Y
X Means YX Means Y
X Means Y
 
The Wonderful World of Wearables
The Wonderful World of WearablesThe Wonderful World of Wearables
The Wonderful World of Wearables
 
Beaming Data to Devices with NFC
Beaming Data to Devices with NFCBeaming Data to Devices with NFC
Beaming Data to Devices with NFC
 
Making Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsMaking Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business Models
 
AppsWorld Keynote
AppsWorld KeynoteAppsWorld Keynote
AppsWorld Keynote
 
Rich Text Editing and Beyond
Rich Text Editing and BeyondRich Text Editing and Beyond
Rich Text Editing and Beyond
 
Android Hardware That's A Little Bit... Odd
Android Hardware That's A Little Bit... OddAndroid Hardware That's A Little Bit... Odd
Android Hardware That's A Little Bit... Odd
 
Google TV For Fun
Google TV For FunGoogle TV For Fun
Google TV For Fun
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Backwards Compatibility: Strategies and Tactics

  • 1. AnDevCon III Backwards Compatibility: Strategies and Tactics Copyright © 2012 CommonsWare, LLC
  • 2. Device Mix image Copyright © 2012 Google, Inc. – reprinted with permission Copyright © 2012 CommonsWare, LLC
  • 3. Device Mix ● The Market Is Not the World ● Kindle Fire ● NOOK Tablet ● Wearables (WIMM, I'm Watch, etc.) ● Miscellaneous non-Market devices ● If You Distribute to These, Take Their Versions Into Account! Copyright © 2012 CommonsWare, LLC
  • 4. Device Mix ● Predictions Sure To Go Wrong ● November 2012: ICS and newer reaches majority status – New device sales – Upgrades for existing devices ● December 2012: Mayan Apocalypse ● April 2013: Android 2.x below 20% ● September 2013: Android 2.x below 5% ● December 2013: Ragnarök Copyright © 2012 CommonsWare, LLC
  • 5. Competing Strategies ● Old API-Centric ● Lowest common denominator ● Today: Android 2.3, maybe 2.2 ● Only deal with newer things when unavoidable ● New API-Centric ● More aggressively support newer capabilities – Particularly with respect to UI ● Today: ICS ● Gracefully degrade for older devices Copyright © 2012 CommonsWare, LLC
  • 6. Forwards, Not Backwards ● Older Ain't Gettin' Any Bigger ● Aim for the increasing market share, not the decreasing share ● Sneezers' Devices ● Bloggers, media, etc. ● Tend towards newer devices ● If you look stale, may impact their interest in you Copyright © 2012 CommonsWare, LLC
  • 7. Forwards, Not Backwards ● Distinctive, Not Decomposing ● Are there new features that can give you a competitive edge? – Even if not all the users can take advantage of them ● It's the Way the (Web) World Works ● IE6-only versus graceful degradation ● Well-trod path, needing Android-specific tactics Copyright © 2012 CommonsWare, LLC
  • 8. Targets and Strategies ● Old API-Centric ● Build target = min SDK version = lowest common denominator ● Target SDK version no higher than min SDK version ● New API-Centric ● Build target = oldest version that has everything you are using directly (or via library) ● Min SDK version = oldest you are supporting ● Target SDK version = current-ish Android version Copyright © 2012 CommonsWare, LLC
  • 9. Validating Compatibility ● Compile-Time: Lint ● Keep your Android SDK tools/ADT updated! ● Will warn you when you try using newer stuff on older minSdkVersion – Requires manual lint run from Eclipse menu ● Use annotations to suppress warnings – @TargetApi(NN) Copyright © 2012 CommonsWare, LLC
  • 10. Validating Compatibility ● Testing ● Directly via emulator ● Directly via available hardware ● Bulk-testing Services – TestDroid Cloud – LessPainful – Apkudo – Etc. Copyright © 2012 CommonsWare, LLC
  • 11. Libraries for Compatibility ● Android Support Package ● Fragments – Large subset, but not everything from native API Level 11+ ● Loaders ● GridLayout ● *Compat Classes – Access to newer constants – Helper methods to get at newer capabilities while gracefully degrading to no-ops/defaults ● Separate Implementations Copyright © 2012 CommonsWare, LLC
  • 12. Libraries for Compatibility ● Action Bar Sherlock ● Implementation of ActionBar for Android 2.x ● Same API as native API Level 11+ ● Nine Old Androids ● Implementation of android.animation framework for Android 1.x/2.x Copyright © 2012 CommonsWare, LLC
  • 13. Ad-Hoc Backports ● Find AOSP Code, Clone, Fix ● New widgets (e.g., Switch) ● Other stuff largely separable from firmware ● Challenges – Finding resources – Dealing with package-private methods Copyright © 2012 CommonsWare, LLC
  • 14. Library/Backport Strategy ● Use as Temporary Scaffolding ● Know which API levels a given library or backport is addressing ● May vary by what you are using ● Remove In Time ● Once you no longer are supporting the older API levels, drop the scaffold and re-test Copyright © 2012 CommonsWare, LLC
  • 15. Java Version Guards ● Android 2.x+ ● Wrap any references to items from newer API level in a test of the API level if (Build.VERSION.SDK_INT>Build.VERSION_CODES.GINGERBREAD) { // do something } Copyright © 2012 CommonsWare, LLC
  • 16. Java Version Guards ● Android 2.x+ ● Wrap any references to items from newer API level in a test of the API level if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.GINGERBREAD) { @TargetApi(11) // do something needing API Level 11+ } Copyright © 2012 CommonsWare, LLC
  • 17. Java Version Guards ● Scenario: AsyncTask ● Serialized if targetSdkVersion >= 14 ● Use executeOnExecutor() to force to classic thread pool model ● Problem: executeOnExecutor() new to API Level 11 ● Solution: version guard block Copyright © 2012 CommonsWare, LLC
  • 18. Java Version Guards ● Android 1.x ● Problem: Dalvik complains if you load a class that refers to items from a newer API level ● Solution – Isolate newer-API items in a separate helper class – Only refer to that helper class within a version guard block Copyright © 2012 CommonsWare, LLC
  • 19. Java Version Guards ● The Old API-Centric Approach ● Use version guard to detect newer API level ● Use reflection to access items that only exist at that API level ● Benefit: can leave build target on older API level – Build target only affects what you directly reference Copyright © 2012 CommonsWare, LLC
  • 20. Versioned Resources ● Use -vNN Resource Set Suffix ● Apply to resources valid for API Level NN and higher ● Scenario – res/values/ = good for anything – res/values-v11/ = good for Honeycomb and newer ● Example – Style in -v11 that references Theme.Holo – Style with same name in default directory that does not reference Theme.Holo Copyright © 2012 CommonsWare, LLC
  • 21. Versioned Components ● Components Valid for Certain API Levels ● Activity only needed on Android 3.1+ ● Different app widgets for API Level 11, older devices ● Technique ● Boolean resource, contained in two resource sets – Default plus -vNN set ● Use boolean resource in android:enabled attribute in manifest – Disabled components do not show up anywhere Copyright © 2012 CommonsWare, LLC
  • 22. Scenario: Preferences ● Goals ● Want to use PreferenceFragments and headers on API Level 11 and higher ● Want preferences to still work on Android 2.x ● Option #1: Different PreferenceActivity Classes ● Use versioned components trick to dictate which one is available ● Use action, not component, in launching Intent ● Reuse preference XML as best you can Copyright © 2012 CommonsWare, LLC
  • 23. Scenario: Preferences ● Option #2: Version Guards ● One PreferenceActivity ● onBuildHeaders() only called on API Level 11+ ● Reuse preference XML as best you can ● Option #3: Backport ● Find current implementation (source, resources) ● Convert to use Android Support fragments ● Most difficulty, but consistent implementation, look-and-feel Copyright © 2012 CommonsWare, LLC
  • 24. QOTD “You’re a Web developer in Java” is the first thing I tell every person mentioning fragmentation. There are no tablets. There are no phones. There’s no Google TV. There is only an unlimited set of configurations of every conceivable feature. Write your application in a dynamic, progressively enhancing manner that follows well- documented patterns and you will be just fine. Jake Wharton Copyright © 2012 CommonsWare, LLC