Google I/O 2019: Unpacking the top news for Android app developers

by: | May 16, 2019

Google I/O, the tech giant’s three-day conference for developers, is a wrap. The mainstream media has written much about the event, largely focused on Google’s live-streamed two-hour keynote event. But from our perch as top Android app developers, the most important questions were answered throughout the week. What are the new Android features that developers can tap into? What’s new with Android development tools? What new types of applications can we design and build for our clients?

Here’s what we learned about the upcoming Android Q, the 10th major release of Android. And it covers other changes to the Android development ecosystem that will impact how we develop mobile apps.

Foldables

Many think foldables are the new “next big thing” for mobile, as several hybrid devices with flexible display technology are starting to hit the market. The key consumer benefit of foldables is multi-tasking. For example, you can watch videos in one section of a screen while chatting with a family member in another. Another benefit is what Google refers to as “screen continuity.” An example is playing a game in a folded screen while on your commute, but then unfolding your device when you arrive home and playing it in a larger format. Some devices supporting foldable technology were already announced at previous conferences, including the Samsung Galaxy Fold and Huawei Mate X. But how should Android developers prepare their apps to support foldables?

android foldable device app development

(SOURCE: developer.android.com)

Adding support for foldables in your Android app

To add app support for multi-tasking (via multiple windows) and dynamic resizing, you have to add resizeableActivity=true to the app manifest file. Doing so, you guarantee that your app will run seamlessly on many devices and form factors (including foldables, desktop mode or freeform windows).

Otherwise, adding resizeableActivity=false, you will tell the system that your app does not support multiple windows. Your app will still resize when unfolded, but it will run in “compatibility mode” and will not work in combination with other applications. The image below shows how an app running in this compatibility mode maintains the same aspect ratio.

Android app development for foldables

(SOURCE: developer.android.com)

Keep in mind that if you DO NOT add resizeableActivity=true, the system will assume that your app fully supports multiple windows and can be dynamically resized.

Up to Android 9.0, only the app in focus would be active. Any other visible apps are paused. This behavior can lead to some undesired situations if the app has to close some resources or stop playing some content when paused. As of Android Q, this behavior is changing. Now all activities remain active when the device is in multi-window mode. This new mode is called multi-resume. The Activity class on Android Q now has a new callback named onTopResumedActivityChanged() that sends a notification when an activity gains or loses the top resumed Activity position. This callback is important when an activity is using a shared single-user resource, such as a camera or microphone.

protected void onTopResumedActivityChanged(boolean topResumed) {
  if (topResumed) {
    // Top resumed activity
    // Can be a signal to re-acquire exclusive resources
  } else {
    // No longer the top resumed activity
  }
}

We’ve only scratched the surface about the promise of foldables and how you can configure your app to be run on these new form factors. Here’s a talk from Google I/O that provides more detail about how foldables work in Android Q.

Android Studio 3.5 Beta

Android Studio, the main tool for Android app developers, has evolved every year. The following sections describe the key features that are included in Android Studio 3.5 Beta.

Memory heap intelligent settings

One of the biggest challenges to building apps with Android Studio is managing battery consumption and memory leaks, which can directly impact your development pace and productivity. Even if your development machine has a maximum of 32 GB of RAM, Android Studio will allocate a 1.5 GB heap size by default. To get a maximum of performance, often we have to manually increase this maximum heap size. The new Android Studio version includes intelligent settings that suggest a recommended heap size based on your available RAM. This feature helps avoid the undesired “Your IDE is running Out Of Memory” prompt. Also, you can set up the maximum heap size through Android Studio’s settings, within “Memory Settings.”

Resource Manager

The new Resource Manager centralizes the display of your active resources including Drawables, Layouts, Animations, and more. It’s also now possible to display your Drawables and its alternative resources. The other cool update is the multi-conversion feature from Scalable Vector Graphics (SVGs) to Vector Drawables. Now you can add a bunch of SVGs that need to be converted into Vector Drawables. The new manager includes a wizard that will guide you through the conversion process, offering warnings if there are file inconsistencies and prompting you to remove or fix them inline. Last but not least, the Layout Inspector comes with a 3D view button that turns the layout preview into a 3D model instantly, allowing developers to see the UI hierarchy as layers of components.

If you want to know more about what’s new in Android Studio 3.5 Beta, see the following I/O session:

Apply Changes (formerly Instant Run)

The idea behind the Instant Run feature is magical. It allows developers to push code changes without building a new APK for each update. However, since it was released as part of Android Studio 2.0, Android developers have struggled to make it work. The main issue relates to incremental compilations made by dex compiler, bringing about undesired runtime crashes. The issue has caused some developers to disable Instant Run whenever they set up a new or existing project. Fortunately, this year Google released a much-needed update and renamed the feature Apply Changes. It’s early and has room for improvement, but from the preview I saw, it seems to be vastly improved.

Android Studio 3.5 support on Chrome OS

For those who are using Chromebooks, Android Studio 3.5 Beta is now supported on Chrome OS. It’s an obviously beneficial update from the company, Google, that owns the hardware (Chromebook), software (Android Studio) and browser (Chrome).

Jetpack Compose

Reactive programming is becoming a first-class citizen in Android development thanks to MVVM and the Kotlin programming language. The Jetpack Compose is a new declarative toolkit, designed to simplify UI development. It includes a new set of Jetpack UI widgets, a Kotlin compiler plugin and is fully compatible with your existing app and code.

With Compose, you can easily create custom views — or Composables — just by adding new functions. It follows a similar programming model as Flutter does with Widgets. All boilerplate code previously required for creating custom UI components — like inheriting Views and ViewGroups, or adding new styles and custom attributes — is now gone! During I/O, I had the chance to stop by the Android sandbox and talk with Jim Sproch, one of the Google engineers responsible for building Compose. He told me that Compose was strongly influenced by the React, Litho, Vue.js, and Flutter programming models. All of these offer a better way to make the UI aware of model changes thanks to the reactivity pattern inherent in these frameworks.

Getting started with Compose

In Jetpack Compose, everything is a function. So, to create a new @Composable, we need to add the following code:

import androidx.compose.*
import androidx.ui.core.*

@Composable
fun Greeting(name: String) {
  Text("Welcome $name")
}

And it can be called by any Activity like this:

class MyActivity: AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle){
    super.onCreate(savedInstanceState)

    setContent {
      Greeting("Ramon Rabello")
    }
  }
}

As you noticed in the Kotlin code above, there’s no longer any need to call either setContentView() or findViewById(). Jetpack Compose does not rely on XML resources. Instead, we just call setContent{ } and everything that it encloses will be displayed on screen properly. The key advantage of this reactive UI pattern is that it promotes composition over inheritance. With Compose, you can build fancy UI components with nested @Composables.

If you want a deep dive into the power of Jetpack Compose, we recommend watching this talk by Romain Guy, Adam Powell, and Jim Sproch. They discuss the prequels of Jetpack Compose and how Android has evolved to support a better reactive UI development:

Also, to learn more, check out the Jetpack Compose guide. Jetpack Compose is early in its experimental stages, so it is not intended to be running in production environments. The APIs for the Jetpack Compose UI library are available open source as AOSP on the frameworks/support/ui directory. And the Compose compiler and runtime code can be found in frameworks/support/compose.

Kotlin Coroutines

Kotlin Coroutines has matured and it is now the core mechanism to do asynchronous calls in Android. The androidx-concurrent library — one of the new components from Jetpack — was enriched with several new CoroutineScopes (such as ViewModelScopes). Coroutine builders eliminate a lot of manual development work that was needed to register and cancel Jobs.

There’s no more need to create a BaseViewModel and implement your own CoroutineScope and CoroutineContext. If you’re not familiar with Kotlin Coroutines yet, I encourage you to take a look at my presentation from The Developers Conference (TDC) about how to integrate Coroutines throughout your app and how it can work seamlessly with Architecture Components.

How does this work? Let’s say that you want to load a user from a database and also retrieve that user and serve it as LiveData. Now you can simply do this:

val user: LiveData<User> = liveData {
  emit(database.load(userId))
}

The above code shows the entire interoperability of Kotlin Coroutines and LiveData. liveData {} coroutine builder was introduced on the lifecycle-2.2.0-alpha01 version launched during I/O. The emit() function is used to dispatch values. Since the type can be inferred by the liveData {} coroutine, we can shorten our code to look like this:

val user = liveData {
  emit(database.load(userId))
}

You can also call it by passing any dispatcher you want for your coroutine:

val user = liveData(Dispatchers.IO) {
  emit(database.load(userId))
}

For more about how you can integrate Kotlin Coroutines across each app layer, check out this talk by Yigit Boyar, Sean McQuillan, Sergey Vasilinetc:

ConstraintLayout 2.0 & MotionLayout

Since it was introduced during 2018’s Google I/O, ConstraintLayout has been the state-of-the-art layout tool that can accommodate almost any design. Along with it came an early version of MotionLayout, which included ConstraintSet, TransitionManager and other animation APIs that can bring realistic and really complex animations to a UI. The most important feature of MotionLayout is that it gives you the ability to define your animation flow entirely in XML.

The MotionLayout is now Beta and includes these new features, among others:

  • Virtual Layouts (enhanced version of ConstraintHelpers), a new timeline view on Android Studio 3.5 Beta that allows you to see your layout animation frame-by-frame
  • The new Flow layout, which provides you a complex grid arrangement of your elements and much more

If you want more details about what’s new in ConstraintLayout 2.0 and MotionLayout, watch this talk by Nicolas Roard and John Hoford:

Security in Android Q

Google emphasized security this year, especially within Android Q. Android Q will include the biometric authentication dialog, first introduced in Android Pie, now with improvements in the authentication flow. The updated biometric dialog is unified and does not prompt users if they have been authenticated using an implicit mechanism, such as face authentication. Another great update in Android Q is support for version 1.3 of Transport Layer Security (TLS), which is now enabled by default for all TLS connections. You can read more about Android’s new security features on developer.android.com.

Looking ahead to Android Q

We’re still unpacking all the news from Google I/O — and we look forward to delivering some great Android apps for our clients once the commercial release of Android Q is available (expected to be in August). For now, Android developers at ArcTouch will have to be content to experiment with the developer preview, which you can download here.

In the meantime, make sure to subscribe to our newsletter to stay up to date about apps, blockchain, and smart products.