Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Safely Update Your App to Android Nougat

DZone's Guide to

How to Safely Update Your App to Android Nougat

Even though it may take a while for phone manufacturers to chew their way through to Nougat, there are some steps you can take to get ready.

· Mobile Zone
Free Resource

Launching an app doesn’t need to be daunting. Whether you’re just getting started or need a refresher on mobile app testing best practices, this guide is your resource! Brought to you in partnership with Perfecto

Android Nougat, the latest version of Google’s mobile OS has started rolling out on Nexus devices. While this is exciting for Nexus owners, based on Android’s history and the latest Apteligent Data Report, it may take a while for Nougat to become available on other devices.

The reason behind this is simple: manufacturers want to make sure their devices and custom software are compatible with the latest version of Android. As a developer, you should be doing the same with your app! There’s nothing more frustrating than putting out a new version, only to see it’s broken on older operating systems. Trust me.

So before you go rushing to add all the new features of Nougat, like multi-window UI and interactive notifications, be sure to upgrade your app safely to ensure a smooth transition for users on every OS version.

Upgrading the SDK

The first thing you’ll need to do in order to leverage the new APIs in Android N is update your app’s settings to target the new SDK. Assuming everything has been downloaded to your system, set your project’s compileSdkVersion to 24. This tells the compiler to build against the latest-and-greatest, and will allow your code to make calls to the new APIs.

Note that this is distinctly different than the targetSdkVersion, which you should also update to 24 if you’re leveraging the new OS features. This setting is an indicator that your app is prepared for and tested on the new version.

Once your app is configured, you can start building against the new APIs.

Checking API availability

Even though your app will compile against the latest APIs, it doesn’t mean your code will work perfectly on existing OS versions. The best thing you can do to ensure your app still works on pre-N systems is to do runtime API checking. This ensures the class or method you want to leverage exists on the device the app is currently running on. If you try to call an N method from an existing OS, your app will crash.

This simple block of code can determine if the device running your app supports  N (or newer), allowing you to add new features without waiting for your entire user base to upgrade.

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N) {
    // Call an N API
} else {
    // Fail gracefully on an older OS
}

Handling Deprecated APIs

If you’re the type of person that loves going through changelogs, well, Android is giving you a treat with their N report here. It has all the details on every change made between API 23 and API 24 (Nougat). This includes additions, modifications, and removals for packages, classes, and fields within the SDK.

Some of these modifications are deprecated, which means code that is no longer supported and may eventually be removed. When a method or class is deprecated, you’ll get a nice little warning from the compiler letting you know which code has been affected so you can make any necessary changes. Even though it is usually a long process, the day may come when the API no longer exists and your code will start to break.

When updating deprecated code, be sure to follow the same checks as you would when adding a new feature. If the new code you’re writing relies on API 24 or higher, you’ll need to perform a runtime version check to ensure your app performs as expected on older versions of the OS.

Test on All Supported Android Versions

At the end of the day, it will be up to proper testing to verify that your app is working on all devices and operating systems you support. Don’t fall into the trap of “it works on my device so it must be fine”. Unfortunately, even the best testing can’t catch everything, which is where Apteligent comes in. Our SDK allows you to monitor for crashes and performance issues in your app to quickly track down bugs that slipped past testing.

Finishing Up

I highly recommend grabbing the Nougat SDK so your app can take advantage of the latest features Android has to offer. Just make sure that you don’t neglect the stability and performance of your app across the rest of your app’s user base. It only takes one bad release to diminish the 5-star rating you’ve worked so hard for, so be thorough and test test test.

Follow these guidelines and your app will be all set as Nougat continues to roll out.

Keep up with the latest DevTest Jargon with the latest Mobile DevTest Dictionary. Brought to you in partnership with Perfecto.

Topics:
android nougat ,android app

Published at DZone with permission of Chris Beauchamp, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}