Over a million developers have joined DZone.

4 Reasons Why Android N is a Game Changer for Developers

DZone's Guide to

4 Reasons Why Android N is a Game Changer for Developers

Google's recently debuted Android N just launched in its developer preview. Here's an overview of Java 8 language support, multiwindow app support, and battery improvements.

Free Resource

Google recently announced that the next version of Android, dubbed Android N, is ready for a developer preview. The preview gives us, as developers, a chance to test our code against the next release before it’s launched, including the new APIs and report any behavioral changes that break us. This release has only been baking for a couple of months, but some of the amazing features are starting to smell great already and we’re very excited about them — you should be too!

Here’s a list of the changes we’re most happy to get our hands dirty with.

1. Java 8 Language Features Support

In general, Java is not considered the sexiest of programming languages, particularly when we’re talking about a platform that supports a subset of Java 7 features only, that are 5 years old now. A modernization is required and luckily, everyone realized that.

All the signs that a change was coming were there when Google announced that Android would be built upon the OpenJDK. This means we get to try out the sweet Java 8 features much sooner than we originally expected.

If you’re ready to move your project to the Jack toolchain which does all the following operations itself: repackages, shrinks, obfuscates, and multidexes your code at once. Then you can enable Java 8 compatibility with a flip of a configuration switch:

android {
  defaultConfig {
    jackOptions {
      enabled true
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8

This will make Jack recognize a subset of Java 8 language features. Don’t worry, though, the part you’re interested in is supported. Here’s what you can use:

  • Default and static interface methods
  • Lambda expressions
  • Repeatable annotations

Well, I’m not sure about repeatable annotations, but it’s a package deal so if you want to write more functional code, you should just take them. Just imagine how much more readable your code will become when you won’t need to deal with object creation for all your listeners, adaptors, and so on.
Here’s a snippet that shows how you can specify a OnClickListener as a lambda:

  v -> Snackbar.make(v, "Hello sweet lambdas", Snackbar.LENGTH_LONG).show()

If you don’t feel super comfortable with the lambdas yet, check out this helpful cheat sheet about Java 8 features and best practices.

The best part of this news is that the lambdas will work for Android versions all the way back to Gingerbread. This is thanks to the fact that the Jack compiler has been in the works for the past 2 years or so. Making Jack the default compiler should also bring some nice benefits to us with our build times. Jack should skip the regular Java bytecode compilation and will produce dex right away. Naturally, some of the libraries out there are going to need and update to work on dex code instead of bytecode.

Hopefully, Jack will also be fully incremental and work with the myriad of annotation processors everyone uses: like DaggerDagger 2Butterknife and so on which are becoming more and more popular.

2. Multiwindow Support in Apps

iOS enabled multiwindow for their apps in version 9 last September, so it was only a matter of time before Android would adopt this as well. If you have a larger device on your hands, you will be able now to watch YouTube and chat on Facebook messenger at the same time! What a time to be alive!

But what is it going to mean for developers? Activity lifecycle is becoming ridiculously complex and it will take time for developers to get used to that. If we throw the fragments lifecycle on top of it, the amount of work to support the basic lifecycle of the views grows significantly.

Image title

Even now, some of us take shortcuts and lock the screen orientation to avoid the need to handle all of those activity lifecycle states. As a result, you’ll have less pain with scaling the UI in both orientations.

It will be interesting to see how many developers will reconsider the orientation locking and enable multiwindow support in their apps. Judging by the API, it seems quite straightforward — basically on par with the complexities of locking orientation. And as we all know, the latter added complexity to Activities and Fragments. Ultimately, I’m super excited to see the lifecycle graph grow further.

3. Battery Improvements: Doze

Doze is the custodian of the Android device power. It kicks in when your phone is not doing much and limits the access of the apps to various resources to save the power.

Doze was already available in Android M, but it only worked while the device was still and not doing anything, like laying on the table. Now with Android N Doze will also work when the device is moving while the screen is off. For the end user, that means a longer battery life — bonus! For the developers, it means you need to start taking care of the limitations that your application will have during doze, as now it can impact your users more often. Most prominently, the CPU and network restrictions are the things that’ll begin to annoy you. However, Doze will also impact the wakelocks, alarms, synchronization, and GPS.

While it will probably make your code a little more complex, it’s a massive user experience enhancement, plus longer battery life means we have more power for doing useful, more impactful things: crush that candy!

4. Notifications

Last but not the least in our list, is revamped notifications. All notifications from the same application can now be grouped together. There also seems to be an option to retrieve user input from the inline reply.

So it really looks like notifications are getting a nice improvement, especially for messaging applications! Which means fewer context switches for the users of the consumer apps, which is a great thing for the ecosystem!

If you’re interested in more details about these changes or want to get your hands on the Android N preview, here’s the documentation that will guide you through all the changes and tell you how to test it. By the way, Android Studio 2.1 preview is also available and it supports Android N, so we get the full tooling support from the day 1.

What are the features of Android N that are most interesting to you? Am I missing anything? Share your thoughts in the comments below and check out the preview documentation. Great times are coming!

android ,lambda ,java 8 ,performance ,development ,mobile ,android development

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}