Illustration by Virginia Poltrack

Now in Android #14

Android 11 Developer Preview 2, Android X releases, articles, videos, game development, and ADB podcast episodes

Chet Haase
Android Developers
Published in
11 min readMar 25, 2020

--

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.

NiA14 in Video and Podcast Form

This Now in Android 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 2

Dial it up to Android 11

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:

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.

AndroidX Releases

There have been various notable AndroidX releases lately.

Beta: CameraX

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:

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.

You can read more about this release in ’s article, check out the CameraX overview, or you can see more about the various modules of CameraX on the AndroidX camera release page.

Stable

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

Alpha

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 startActivityForResult()/ onActivityResult() and requestPermissions() / 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.

Articles

Many technical articles have landed on the Android Developers publication recently, including:

Themes Overlay

posted the next in his series of Android Styling articles:

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

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

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

wrote an article about external storage changes in Android 11:

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

and posted a three-part series on cancellation and exceptions in Kotlin coroutines:

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:

These articles derive from the presentation that and gave at KotlinConf:

Videos

We’ve posted a few videos recently as well:

Accessibility

Shailen Tuli and 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.

Kotlin Vocabulary

Three more episodes of the ongoing Kotlin Vocabulary series are now available:

posted Suspend functions, which explains how the Kotlin compiler transforms coroutines under the hood (this is an alternate form of the article he posted, which is discussed above):

posted Collections and sequences, which discusses when to use Kotlin collection APIs for eager evaluation, versus sequences for lazy evaluation:

Finally, I posted D8, R8, and enums, which is the video version of the When using enums and R8 article I mentioned above:

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:

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.

In which I talked with Sumir Kataria and 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.

Now then…

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.

--

--

Chet Haase
Android Developers

Past: Android development Present: Student, comedy writer Future: ???