Image for post
Image for post
Illustration by Virginia Poltrack

Now in Android #31

Modern Android development content, documentation enhancements, AndroidX releases, articles, and a podcast episode

Chet Haase
Dec 16, 2020 · 10 min read

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

NiA31 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.

Modern Android Development

Image for post
Image for post

Get Your #MADScore

In conjunction with the MAD Skills series, we wanted to have a little fun and offer an opportunity for you to answer that burning question: How MAD are you? To find out, install and run the MAD Scorecard plugin in Android Studio. It creates a card for you, showing how well your app scores in the four pillars of modern Android development, which you can then share to Twitter with the #MADscore hashtag.

Go to the MAD Score site to get the details, or check out more about it on Christopher Katsaros’s blog:

MAD Skills: Material Design Components

Meanwhile, the MAD Skills series continues to roll on, with technical content about modern Android development. Last week, the series on Material Design Components finished up. Since the last Now in Android, the team posted 3 more episodes:

#4: Material Motion
In the fourth MDC episode, Nick Rout talks about the four patterns of motion in Material and how to implement them in your applications. He walks through the Reply sample app, and a codelab based on that app, to show how it works in practice.

#5 Community Tip from Zarah Dominguez
The fifth MDC episode came to us from Zarah Dominguez, a Google Developer Expert, who talks about how her team uses the Material catalog app, both to see how things look in practice and what the source code looks like as an example of how to implement them.

#6: Live Q&A
The final MDC episode was, just like the previous series on App Bundles and Navigation, a live Q&A with MDC experts on the developer relations and material engineering teams. We got lots of questions from you on Twitter and in real time on YouTube during the Q&A. We didn’t have time to answer all of them, but we make… material progress.

If you missed any of the content in the MDC series, Nick Rout wrote up a summary of the series in this wrap-up article, with links to all of the relevant videos and articles, along with associated samples, doces, codelabs, and more.

MAD Skills: Kotlin and Jetpack

This week, there’s a new MAD Skills series on Kotlin and Jetpack. Specifically, it’s about how to use Kotlin in conjunction with many of the Jetpack APIs. Florina Muntenescu introduced it thusly:

#1: Using KTX
The first episode in the series is on using KTX, the Kotlin extensions we offer which provide improved, simpler approaches for various platform and Jetpack libraries. Florina discusses KTX in general, with examples in both platform and Jetpack APIs, showing how she uses them when using LiveData and ViewModel.

Or in article form:

#2: Simplifying APIs with Coroutines
In this second episode, Manuel Vivo explains how to use Kotlin coroutines to improve the experience of using existing APIs for Kotlin developers. For example, you can create adapters that simplify the complexity of nested callbacks with coroutines. He works through an example of creating a simpler API for Fused Location Provider to show how to do this in practice.

Or in article form:

Look for more Kotlin/Jetpack episodes in the next few weeks, which will show up both on the YouTube playlist as well as in article form in the Android Developers publication.

For ongoing content, be sure to check the MAD Skills playlist on YouTube, the articles on Medium, or this handy landing page that points to all of it.

Documentation

Permissions

Image for post
Image for post
The high-level workflow for using permissions on Android

There have been several changes to permissions in the last few releases, as we continue to focus on user control and transparency of user data. Sometimes this entails work from developers to keep up with the latest updates and behavior changes, so we’ve been working on our documentation to help with that process.

As part of this effort, we’ve recently made several substantial improvements to the Permissions on Android guide. This site now provides more streamlined guidance on how permissions work, along with best practices for using permissions in your app. In particular, you should evaluate whether you actually need to declare permissions, which are not necessary for many common use cases.

The DAO of Room

A couple of the Room library guides were overhauled to clarify how to use some of the aspects of the APIs:

Using Data Access Objects (DAOs) with Room provides an overview of using the DAO interface, including using the built-in query methods as well as custom methods using the @Query annotation.

Writing asynchronous DAO queries covers more details about how to write queries which happen off of the UI thread, which is pretty much required for database interactions. The guide walks through several alternatives you can use, depending on your language and asynchronous API preferences.

AndroidX

Among the plethora of recent alpha, beta, and RC releases of various AndroidX libraries were the following stable releases:

  • Browser 1.3.0: This latest release introduces the ability to pass free-form commands with the Trusted Web Activity APIs, along with other features such as improvements to setting colors on custom tabs.
  • Media2 1.1.0: This release has a slew of bug fixes, along with additional APIs for handling media tracks and for interop with the AndroidX Media library.
  • WearInput 1.0.0: This first version of WearInput brings support for WearableButtons to the AndroidX libraries.

There were also some stable bugfix releases, including Exifinterface 1.3.2, Media 1.2.1, and Navigation 2.3.2.

Android Studio

Image for post
Image for post

Jamal Eason posted an article announcing the next release of Android Studio: Arctic Fox is now in the canary channel and ready to try out. The first thing you’ll notice about this release is a new naming and versioning scheme, which the article discusses in detail. Beyond that, some of the things to check out in the release include a UI for pairing with a device for wifi debugging (MacOS only for now), a layout validation tool, and continued support for Jetpack Compose development. (Note that you always have to use the canary version of Studio to work with Compose in its current very-early state.)

Murat Yener also posted about new Android Studio stuff, in his article on the new alpha release of the Android Gradle plugin, version 7.0.0-alpha01. Note that AGP also went through a version-naming change. AGP will now track the Gradle release versions instead of being coupled with the Android Studio versions. Which explains why it looks like this version skipped or forgot a couple of versions since the current 4.2 release. The article also talks about some of the recent API changes in AGP 4.2.

Articles & Videos

ListAdapter

Meghan Mehta posted another article in her series on RecyclerView. Although RecyclerView is not new (and most Android developers are probably already using it in their apps), we found that the documentation and examples for some of the fundamentals were a bit hard to find (at least in our docs and articles), so she’s been taking a run at explaining how to use some of the fundamentals, along with sample code to show how to do it in practice.

In this latest article, Meghan talks specifically about using ListAdapter, which provides an easy way to get some great functionality for your RecyclerView, including better performance and automatic item animations. ListAdapter uses DiffUtil to determine the specific changes that occurred, which RecyclerView needs for optimal performance and animations.

Performance

I continued my exploration into startup performance with a two-part series on App Startup, an AndroidX library that reached 1.0 recently. Part one takes a look at how content providers are often used to instantiate libraries, and how that can cause a hidden impact on application startup time.

Part 2 investigates how to use the App Startup library to remove those hidden content providers and pool requests for lazily initializing libraries instead.

Location, Location, [Better GPS] Location

There’s an article on the Android Developers Blog that details improvements that we’ve added to the location system and APIs to make it possible to get more accurate location information in cities. The article discusses the problem of deriving GPS location in cities, where the default assumption of GPS technology using line-of-sight is tricked by how signals are bounced off of tall buildings. (Tor and I talked with Marc Stogaitis from the location team about this in an ADB podcast way back in 2014: the phenomenon is called “urban canyons”).

The team has integrated 3D building models for major cities to achieve much more accurate location results. Version 2 of this tech is available on some Pixel devices now. An earlier version is already available to the wider ecosystem, and this latest version will be similarly available early next year.

Of course, all of this is a user feature, and Now in Android is for developers. But I wanted to call it out here because (a) I found the article and technology interesting and(b) there is a developer call-out here, which is to use Fused Location Provider (FLP) to get access to this enhanced location data.

Also, there’s a new API in FLP that allows you to get current location information much more easily by just asking for the current location and getting a result vs.subscribing to ongoing location changes and then unsubscribing after you get the first result. Check out the the docs for FLP’s getCurrentLocation() API, the new CurrentLocationKotlin sample, and the article for more information.

Jetpack Compose Migration

Chris Banes has been migrating his app Tivi from an app that uses the current UI Toolkit to one using Jetpack Compose. He finished a major part of that migration, with the entire UI now being written in Compose, and resurfaced to report some interesting results on APK size (much smaller!), method count (smaller!), and build duration (a little smaller!).

CameraController in CameraX

The CameraView API in CameraX was doing too much, handling both UI and controller logic. So that logic has been refactored into PreviewView and the new CameraController class. This article describes how to use CameraController, and how that functionality compares to what you might have been using previously in CameraView.

Podcast Episodes

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 153: Ok, Ok, Ok

Romain Guy, Tor Norbye and I talked with Jesse Wilson from Square about some of the popular open-source libraries he’s worked on, including OkHttp, Okio, and [Ok]Moshi. We talked about these libraries, and others, and about Android, library, framework and Kotlin development. And about that nasty habit some engineers have of turning a feature request or minor annoyance into a project of creating a new open-source library instead.

Now then…

That’s it for this time. So get your MAD scorecard! Go MAD for more MDC and Kotlin/Jetpack content! Read the latest Permissions and Room documentation! Download the latest AndroidX stable releases! Read new articles on ListAdapter, startup performance, improved GPS location, Jetpack Compose migration, and CameraController! Listen to the latest ADB podcast And come back here soon for the next update from the Android developer universe.

Android Developers

The official Android Developers publication on Medium

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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