Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android Design Patterns and Best Practice

You're reading from   Android Design Patterns and Best Practice Create reliable, robust, and efficient Android apps with industry-standard design patterns

Arrow left icon
Product type Paperback
Published in Dec 2016
Publisher Packt
ISBN-13 9781786467218
Length 370 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Kyle Mew Kyle Mew
Author Profile Icon Kyle Mew
Kyle Mew
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Design Patterns FREE CHAPTER 2. Creational Patterns 3. Material Patterns 4. Layout Patterns 5. Structural Patterns 6. Activating Patterns 7. Combining Patterns 8. Composing Patterns 9. Observing Patterns 10. Behavioral Patterns 11. Wearable Patterns 12. Social Patterns 13. Distribution Patterns

Targeting platform versions

To keep up with the latest technology, new versions of the Android platform are released frequently. As developers, this means we can incorporate the newest features and developments into our applications. The obvious drawback to this is the fact that only the very newest devices will be able to run this platform and these devices represent only a tiny proportion of the entire market. Take a look at this chart taken from the developer dashboard:

Targeting platform versions

The dashboard can be found at developer.android.com/about/dashboards/index.html and contains this and other up-to-date information that is very useful when first planning a project.

As you can see, the vast majority of Android devices still run on older platforms. Fortunately, Android makes it possible for us to target these older devices while still being able to incorporate features from the most recent platform version. This is largely achieved through the use of the support library and by setting a minimum SDK level.

Deciding which platforms to target is one of the first decisions we will need to take, and although it is possible to change this at a later date, deciding early which features to incorporate and knowing how these will appear on older devices can greatly simplify the overall task.

To see how this is done, start a new Android Studio project, call it anything you choose, and select Phone and Tablet as the form factor and API 16 as the Minimum SDK.

From the list of templates, select Empty Activity and leave everything else as is.

Targeting platform versions

Android Studio will automatically select the highest available SDK version as the target level. To see how this is applied, open the build.gradle (Module: app) file from the project pane and note the defaultConfig section, which will resemble the following code:

defaultConfig { 
    applicationId "com.example.kyle.factoryexample" 
    minSdkVersion 16 
    targetSdkVersion 25 
    versionCode 1 
    versionName "1.0" 
} 

This ensures that our project will compile correctly for this range of API levels, but if we were building an app that we intended to publish, then we would need to inform the Google Play store which devices to make our app available on. This can be done with the build.gradle modular file, like so:

minSdkVersion 21 
targetSdkVersion 24 

We would also need to edit AndroidManifest.xml file. For the example here, we would add the following uses-sdk element to the manifest node:

<uses-sdk 
    android:minSdkVersion="16" 
    android:targetSdkVersion="25" /> 

Once we have determined the range of platforms we wish to target, we can get on and see how the support library allows us to incorporate many of the latest features on many of the oldest devices.

You have been reading a chapter from
Android Design Patterns and Best Practice
Published in: Dec 2016
Publisher: Packt
ISBN-13: 9781786467218
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image