Image for post
Image for post
Illustration by Virginia Poltrack

Now in Android #17

Android 11 DP3, Articles on CameraX, Dagger, Kotlin, and rendering, AndroidX releases, and an ADB podcast on IME animations

Chet Haase
May 6 · 7 min read

Welcome to Now in Android, your ongoing guide to what’s new and notable in the world of Android development.

NiA17 in Video and Podcast Form

This is also offered in video and podcast form. It’s the same content, but with less reading required. The article version (keep reading!) is still the place to come for links to all of the content that’s covered.

Video

Podcast

Click on the link below, or just subscribe to the podcast in your favorite client app.


Android 11: Developer Preview 3

Image for post
Image for post
Dial it up to Android 11

The latest preview of Android 11 launched recently, with some new functionality, in addition to the fixes that ongoing preview releases generally bring.

Debugging Improvements

Catching real-world problems can be difficult, with devices and situations that vary widely from what you have available for developer testing. It’s helpful to be able to get more information about crashes and problems in the field, where those problems occur.

There are a couple of improvements in Android 11 that should help. First is a new API for querying information about reasons why your app exited, ActivityManager.getHistoricalProcessExitReasons().

Also, for NDK developers, Android 11 offers GWP-ASan, a low-overhead library that helps track memory issues on user devices, making it easier to catch these hard-to-catch problems in the field. We’re already using it for platform libraries; now you can enable it for your application.

Wireless debugging

Speaking of making debugging easier…

Image for post
Image for post
Much of software development is a porting problem, USB ports included.
Image for post
Image for post
Wireless debugging at last

In these days of uncertainty, we value those things in life that we can depend on. Like never having enough USB ports for all of the things we need to connect to our machine.

That’s why the new wireless debugging feature should be a welcome addition to all Android developers’ toolbox. For now, you can access this new facility via the command-line, but expect future improvements as we keep working on it.

ADB Incremental APK Installation

As part of our efforts to improve Android game development, we’ve added a new tool to make pushing large APKs much faster (up to 10x!). The process involves signing your app with a new APK signature scheme and using an updated ADB command-line tool. Also, note that this only works on Pixel4/4XL devices for now, since it required device-level file system changes, but the capability will be available with all new devices that launch with Android 11.

Data Access Auditing

Android 11 also adds the ability to audit private data access happening within your app. Now your app can see when it (or maybe libraries that it depends upon) accesses data that requires user permission. This API is useful if you have a very large app or use third-party libraries, and you need to better understand how data’s being accessed, either by design or unexpectedly.

Jeremy Walker has a written a Kotlin sample that teaches you how to use the API, including using a separate module/library that accesses data in ways you wouldn’t expect. (Don’t worry, you learn how to identify code like that.)

And so on…

Check out the Blog for an overview of the DP3 release, and the Android 11 Developer Preview site for more information about these DP3 features along with everything else that Android 11 has to offer. And if you haven’t yet tried your app on Android 11, now’s the time; our extended preview period exists to ensure that the final release provides the maximum compatibility and robustness possible, so test it out and let us know if you have any problems.


Articles

CameraX Preview

Husayn Hakeem wrote an article showing how to use CameraX to create a simple preview view. Instead of manually managing the surface, configuration, rotation, and everything else, you can ask CameraX to manage it for you. It creates a custom view and manages the surface internally. You can implement useful features like tap-to-focus and pinch-zooming, all without the complexities of dealing directly with the surface that holds the camera feed.

Dagger in Android Studio

Manuel Vivo wrote an article on a new feature in Android Studio 4.1 canary builds that supports Dagger. In particular, you can use the IDE to see how, and from where, your code is being called with a Dagger injection, as well as what functions are being injected from a call site.

Kotlin objects

Murat Yener wrote another article in the Kotlin Vocabulary series which explores the Kotlin object keyword. We use static in Java to create singleton items, but there is no static qualifier in Kotlin. Instead, we use object, which defines and creates a single instance. Objects can be used to implement the Singleton pattern (with less boilerplate code!), as well as anonymous inner classes in Kotlin.

As usual for Kotlin Vocabulary articles, Murat’s article shows what’s really going on under the hood, by showing the decompiled bytecode implementation.

Dynamic Refresh Rates

Ady Abraham, from the graphics engineering team, posted an article on the Android Developers Blog about variable refresh rate, a feature available on some newer devices that’s enabled by new APIs in Android 11.

For many years, the typical refresh rate of devices has been pegged at around 60 frames per second, which gives apps around 16ms to render their content for each frame. If apps could not make that frame rate, but wanted to maintain a consistent rate, they’d have to drop to half of the default rate, delivering new frames at only 30 frames per second. With variable refresh displays, which can support speeds of sometimes 90 and even 120 Hz, there are both higher frame rates possible as well as more variability for backoff rates if an app can’t achieve the highest rate possible.

This article talks about how the rendering system works in general, and how apps can request different rendering rates from the system, using new APIs in Android 11.


AndroidX

Various AndroidX libraries were released recently (as they usually are, since AndroidX ships changes every 2 weeks). They are all incremental mid-Alpha/Beta/RC releases, so I’ll skip the details except for a couple I’d like to call out in particular:

Navigation 2.3.0-alpha06

This release contains a new Kotlin DSL for creating navigation graphs dynamically (compared to the traditional mechanism of creating the graphs with the Nav Graph Editor in Android Studio, along with its underlying XML code). One of the use cases that it supports is the new Dynamic Feature Navigation capability, where you can now use the Navigation component to navigate to destinations which are in not-yet-installed dynamic feature modules.

Ben Weiss created a new sample to show how this works, and there’s also new guide on the new navigation DSL.

Fragment 1.3.0-alpha04

This new fragment library version has a new Fragment Result API that takes the place of the now-deprecated setTargetFragment(). Better yet, there’s a new guide on how to pass data between fragments.


Android Developers Backstage: the Podcast

Image for post
Image for post

There’s been another episode of Android Developers Backstage posted since the last Now in Android.

Check it out at the link below or in your favorite podcast client.

ADB 138: Animated IME: Oh, My!

I’ve already gone on and on about my favorite feature in Android 11: synchronized IME animations, with which developers can control and listen in on keyboard animations to create more seamless app/keyboard interactions. In this episode, Romain Guy, Tor Norbye and I talked with Jorim Jaggi, Adrian Roos, and Taran Singh from the window manager engineering team about how it all works.

Now then…

That’s it for this time. Go check out the latest Android 11 preview! Read about CameraX preview views! Play with Dagger features in Android Studio! Learn about how Kotlin objects enable easy Singleton coding! Discover more about Android’s rendering pipeline and how dynamic refresh rate works! Download and play with the latest navigation and fragment AndroidX libraries! Listen to the latest ADB podcast episode on IME animations! And come back here soon for the next update from the Android developer universe.

Android Developers

The official Android Developers publication on Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade
A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store