Now in Android #14
Android 11 Developer Preview 2, Android X releases, articles, videos, game development, and ADB podcast episodes
Welcome to Now in Android, your ongoing guide to what’s new and notable in the world of Android development.
Hey everyone: I hope everyone is staying safe and healthy. If you’re hunkered down sheltering and working at home like I am these days, maybe you want some developer bits to dive into. Here are some recent pieces from the Android team that are worth checking out.
Android 11: Developer Preview 2
I talked about the first preview for Android 11 in episode #13. And now, the next release has already dropped. Dave Burke posted an overview of the release on the Android Developers Blog. Check out the preview for updates to some of the features that were already in the release, as well as some new shiny features that are just now available, including my personal favorite feature: IME animation control.
Synchronized IME Animations
For a platform developer, all new features are like our children: we have no favorites. But really, IME animation control is my favorite-favorite feature. You’ve been asking us for this feature (and we’ve been wanting it ourselves!) for several years, and now it’s here.
The idea is that the IME (keyboard) pops up on its own when keyboard entry is needed. This is the functionality the user needs, but it doesn’t provide the experience that users or developers want, because the appearance creates a visual discontinuity by simply popping into place, causing the apps to snap into their adjusted layout given the change in available screen real estate. The keyboard actually does animate in… but the app snaps instantly to the post-animation size, causing this visual hiccup.
What developers want, and what the new APIs provide, is the ability to both listen to information about the IME position as it animates in (so that apps can synchronize their own animations to suit) and to control the animation of the IME. Between the listener and the animation control, applications now have enough capability to create experiences that blend the change in the application UI with the animation of the IME itself, providing a much better experience.
By the way, this feature has actually been in the works for a while. In fact, it nearly hit Android 10… but wasn’t quite ready, so we had to finish it up for Android 11 instead.
NDK Image Decoder
Another new API added in Android 11 is an image decoder for the NDK, especially for you native-code developers out there. If you’re currently jumping up through JNI to decode your images through the platform APIs or worse (from an app-size standpoint at least), bundling other libraries to handle image decoding, then we have a deal for you…
You can now use the new NDK
ImageDecoder API to handle images in common formats (such as JPEG, PNG, GIF, WebP, and HEIF). Check out the NDK guide for more information. Also check out the ImageDecoder sample, especially Texture.cpp, to see how it works.
Nullability in Android 11
We also added new nullability annotations to the SDK APIs in Android 11.
David Winer posted this article on the Android Developers Blog:
Handling Nullability in Android 11 and Beyond
Last May at Google I/O, we announced that Android was going Kotlin first, and now over 60% of the top 1000 Android apps…
which talks about nullability in Kotlin and how that works with APIs written in the Java programming language (which supports nullability through annotations, as opposed to Kotlin’s language support for nullability).
Specifically, Android 11 introduced new annotations across the API that may introduce new warnings and errors when building (it’s a good thing! Catch those problems at build time instead of at runtime!). Some APIs that used to have @RecentlyNullable or @RecentlyNonNull (which may throw warnings from the Kotlin compiler when used incorrectly) were upgraded to @Nullable and @NonNull (which generate build-time errors instead). We also added new @RecentlyNullable and @RecentlyNonNull annotations to APIs that did not yet have any annotations. So build your apps and look for new warnings and errors to fix.
But Wait, There’s More!
Other things we’ve added to Android 11 since the last preview release include:
- There is now a hinge angle sensor for foldable devices.
- NNAPI added a “hard-swish op,” which enables faster and more accurate training. I’m not sure of the details here, but I like the name. Bonus points for the very academic article that explains the theory behind swish activation functions if you want to know more.
- Starting in Android 11, apps that want to use the microphone or camera from a foreground service need to add the foregroundServiceType attribute to their manifest, just like the location changes in Android 10. Note that we also talked about this change with the engineering team in episode 133 of the ADB podcast, Power Play.
- Apps can now request variable refresh rates on supporting devices.
- The emulator now supports both front and back cameras.
The whole reason that we do preview releases is to give you a chance to try your app out on these early releases to make sure that things are working for you. This extra time gives you a chance to either fix problems if you see any, or to report issues for us to fix before we finish up the release and ship the final version. To help you, we’ve added a new settings screen in developer options where you can toggle various behavior changes to see whether they have any impact on your situation. So now would be an excellent time to try out Android 11 and see how it’s working for you.
Read Dave Burke’s post for more information, or go get all of the details and the bits on the Android 11 Preview site. And please give us feedback if you have any, or even fill out a survey to let us know your thoughts on the updates and changes.
There have been various notable AndroidX releases lately.
The CameraX library, created to make it easier to develop camera functionality (even across a diverse device ecosystem) has now entered Beta. This means that the API will remain steady as the team fixes issues before the library reaches stable.
In case you haven’t looked at it since it was first released in alpha form, some of the improvements of the Beta release include:
- Explicit camera initialization with ProcessCameraProvider
- Choosing which camera (front or back) to be used with one or more use cases via the new CameraSelector API
- Easier access to information about and control of camera features like zoom and focus with CameraInfo and CameraControl
Another release worth noting is the still-in-alpha (alpha08 as of this writing) Camera View module, which provides helpful components related to Views for camera applications.
A few libraries went stable with mostly bug fixes and minor features, including:
- Fragment 1.2.3
- Paging 2.1.2, which fixes an issue with 2.1.1 where some partially-implemented APIs were inadvertently exposed a bit too early, causing potential build or runtime problems (read: stop using 2.1.1, upgrade to 2.1.2 now)
- Room 2.2.5
- Webkit 1.2.0, which includes the ForceDark API to control rendering WebViews in dark mode
- WorkManager 2.3.3 and 2.3.4
Of particular note in the many libraries hitting alpha versions recently is
Activity 1.2.0-alpha02, which adds support for ActivityResultRegistry, letting you handle
onRequestPermissionsResult() flows without overriding methods in Activity or Fragment. If you’re using this, you might also want to check out Fragment 1.3.0-alpha02, which adds support for these new APIs. Also check out the updated guide on Getting a result from an activity.
Many technical articles have landed on the Android Developers publication recently, including:
Nick Butcher posted the next in his series of Android Styling articles:
Android Styling: Themes Overlay
In previous articles in this series on Android styling, we’ve looked at the difference between styles and themes…
This article covers the use of theme overlays to set a small number of attributes, which are then overlaid on top of the rest of the theme attributes in the hierarchy. Overlays are contrasted with full themes, which are used to specify a larger set of attributes, whereas overlays focus on just a small, targeted subset.
App Bundle Testing
Ben Weiss wrote an article about how to test Android App Bundles:
Testing APKs is relatively straightforward; you can just send around the APK in question for your testers to install. But in the world of App Bundles, where the binary you build is not the same as the APKs downloaded from the Play Store, how can you make this process work for your testers?
Ben has you covered, with an article that details how you can upload bundles that are made available specifically for a testing audience. The article also introduces a completely new feature of Play Console — testers can now easily install historical versions of your app by following a link, so they can access the exact version that helps reproduce a bug, or they can test the in-app update flow.
When, Enums, and R8
I posted an article in the ongoing Kotlin Vocabulary series:
This article is a subset of a presentation that I did with @Romain at KotlinConf, where we talked about how various features of Kotlin work down in the bytecode, and how the R8 compiler optimizes the inherent overhead of some of these features:
In the case of enums, adding a
switch statement (or a
when statement, in Kotlin) causes the generation of an extra class and array. Using the R8 compiler can fix that.
The Suspend Modifier — Under the Hood
Manuel Vivo posted this article:
which explains how the Kotlin compiler transforms coroutines under the hood. (There’s also a video with similar content — see below).
Storage in Android 11
Yacine Rezgui wrote an article about external storage changes in Android 11:
Modern User Storage on Android
To protect user data and reduce the amount of space consumed by apps, Android 10 introduced changes to the behavior of…
This article discusses some of the large changes that were made to scoped storage in Android 10 as well as the changes intended for Android 11.
Kotlin Coroutines: Cancellation and Exceptions
Part 1 provides a quick overview of coroutines, including defining and explaining the necessary pieces: CoroutineScope, Job, and CoroutineContext:
Part 2 covers (wait for it…) coroutine cancellation. The article describes how to cancel specific jobs as well as entire CoroutineScopes. It also discusses how cancellation is cooperative, and how to properly abandon work in a coroutine that has been cancelled.
Part 3 wraps up the series by discussing what to do when things don’t go as planned: how to properly handle exceptions in your coroutine code. For example, an exception in a coroutine will, by default, cause the cancellation of all coroutines in its CoroutineScope to be canceled, but you can avoid this situation by using SupervisorJob:
Exceptions in Coroutines
Cancellation and Exceptions in Coroutines (Part 3) — Gotta catch ’em all!
We’ve posted a few videos recently as well:
Shailen Tuli and Lyla Fujiwara posted this video to help developers understand what to do to create accessible applications:
This is one of our longer-form videos that takes a full conference session and packs it into a video for easier consumption. Speaking of accessibility, the Principles for improving app accessibility guide now explains how your app is more accessible “for free” when your custom UI widgets extend from appropriate UI subclasses.
Three more episodes of the ongoing Kotlin Vocabulary series are now available:
Google for Games
Like many developers and companies, we were looking forward to going to the Game Developer Summit (GDC) this year, and we’re sorry we didn’t get to see you to see you all in person. Although the event did not happen as planned, we’ve put together a virtual Google for Games Developer Summit as a cross-Google effort, and there are many new Android tools and features to cover. Things like:
- Native profiling capabilities are now added to Android Studio’s System Trace tool
- Support for native debug symbols in Android Vitals to help you diagnose crashes in the field
- Easier access to Google APIs for Unity developers
You can also sign up for previews such as:
- A game development extension for Visual Studio to make it easier to add Android support to your cross-platform game
- A new Android GPU inspector tool
There’s an article on the Android Developers Blog that gives an overview of the various things that we’ve announced and released. There’s also a Google for Games Developer Summit playlist on YouTube with the keynote and a host of technical sessions from Google.
ADB Podcast Episodes
There have been a couple of episodes of Android Developers Backstage posted since the last Now in Android. Check them out at the links below, or in your favorite podcast client:
Episode 133: Power Play
In this episode, Chet talked with Amith Yamasani, Makoto Onuki, and Kweku Adams from the framework team about power…
In which I talked with Amith Yamasani, Makoto Onuki, and Kweku Adams from the framework team about power management. We waxed poetic about the heuristics the system uses to kill tasks, doze mode and how the system tries to save battery, TrimMemory requests, JobScheduler (the underlying platform facility used by WorkManager), AppStandby buckets, and more.
Episode 134: All Work No Play
In this episode, Chet talks with Sumir Kataria and Rahul Ravikumar from the Android Toolkit team about Work Manager…
In which I talked with Sumir Kataria and Rahul Ravikumar from the Android Toolkit team about Work Manager, an AndroidX library for deferrable background work. We talked about recent changes such as on demand initialization, new lint checks, and more.
That’s it for this time. So go learn about Android 11 DP2! Check out the CameraX beta release and other AndroidX releases! Find a slew of new technical articles and videos on the Android Developers publication and YouTube channel! See what’s happening in the world of Android game development! Check out the latest ADB podcast episodes! And come back here soon for the next update from the Android developer universe.