Android 12 for Developers — Changes and improvements in user experience and design

Frederick Klyk
8 min readMar 17, 2022

--

Photo by Lerone Pieters on Unsplash

Starting in Q1 2021, Android developers have enjoyed exploring the new Google APIs and behavior changes for the forthcoming Android API 31. The Developer Previews phase focused on developer community feedback for the APIs, while the current Beta Release phase focuses on Android Beta users’ compatibility experiences. In the final phase, apps and libraries are then compiled and tested against the official API 31 SDK. In addition, the corresponding libraries are updated, and their developers are informed of potential problems. Ultimately, after various release candidates, the final release of Android 12 will be published with the corresponding news.

Due to the advanced beta phase, it is worth taking a closer look at some of the new functionalities and APIs discussed in this blog post from both a developer and user perspective.

A detailed overview of the status of each phase can be found in the release notes:
https://developer.android.com/about/versions/12/release-notes.

As a developer, in addition to the emulator, you have the option of obtaining an Android 12 beta build with the following Google Pixel devices, in which you can download after the successful flash process (https://developer.android.com/about/versions/12/download) is automatically supplied with over-the-air updates of recent preview versions:

  • Pixel 3 and 3 XL
  • Pixel 3a and 3a XL
  • Pixel 4 and 4 XL
  • Pixel 4a and 4a (5G)
  • Pixel 5

User Experience und Design

Update der Widgets API

In the Google blog post “What’s new in Android 12 Beta”, Android 12 is advertised with the biggest design change in Android history, which is associated with the term “Material You”.

We rethought the entire experience, from the colors to the shapes, light and motion, making Android 12 more expressive, dynamic, and personal
(see: https://android-developers.googleblog.com/2021/05/whats-new-in-android-12-beta.html)

To improve the user and developer experience, the Widgets API has undergone a major overhaul. Visual improvements from Android 12 include:

• Customizable rounded corners for both the widget background and any view inside the widget,
• Dynamic colors can be used and customized for widgets using themes such as following common attributes,

  colorAccent
colorBackground
textColorPrimary
textColorSecondary

• Additional APIs to configure the size of widgets more reliably on different devices and to define a maximum resizable size of widgets,

  android:targetCellWidth=”3"
android:targetCellHeight=”3"
android:maxResizeWidth=”200dp”
android:maxResizeHeight=”80dp”

• In the Widget Preview view, scalable XML layouts with an additional description can now be used instead of static images, so that the best possible display is guaranteed on the various end devices.

android:previewLayout="@layout/widget_preview"android:description="@string/widget_preview_description"

• Responsive layouts can be provided to change the view of widgets when resizing, e.g. from a list to a grid layout,

• Various instructions for backwards compatibility with the new API functions in the official guidelines.

In addition to the visual improvements, support for stateful behavior has been added for the following components:

• CheckBox
• switches
• Radio button

To be able to use the new state-based behavior, the app must store the states and provide events for the state changes, while the widgets themselves remain stateless.
The update of this API is in some functionalities a long overdue and, despite everything, very successful progress in the display and use of widgets. From the developer’s point of view, the new features and possibilities are easy to implement and from the user’s point of view, both the user experience and the perceived product maturity of the app are increased.

Splash Screen API

Another new feature added with Android 12 is the Splash Screen API.
A splash screen is visual feedback displayed to the user while the app initializes. For example, the user does not see an empty screen, but an app icon or animation while the app performs various background services.
In addition to increasing the user experience for the user, developers receive a lean and easy-to-use API to implement a splash screen.
Previous was a custom implementation that could be implemented in a variety of ways.

On June 30, 2021, the first alpha version of the Core Splash Screen API was released:

• androidx.core:core-splashscreen:1.0.0-alpha01
• Backwards compatibility for the new Splash Screen APIs up to API 23
• API can only be applied when the compileSdkVersion is declared on Android 12 (API 31).

The splash screen is always displayed to the user in the following situations:

Cold start: When the app process is not running, and the app is started
Warm start: When the app process has started but the activity has not yet been created or was previously destroyed

The splash screen is not displayed with a hot start, i.e. e.g. when the app was brought to the background and the app is opened again (before the system destroys the activity).

The splash screen is implemented using a style theme that must have been defined as the parent Theme.SplashScreen. The following core attributes are available:

windowSplashScreenBackground: the background color of the screenwindowSplashScreenAnimatedIcon: Splash Icon, preferably a vector drawable, can be static or animated.windowSplashScreenAnimationDuration: Time for how long the splash screen should be displayed (max = 1,000ms)postSplashScreenTheme: Theme to be used as soon as the splash screen is no longer visible

In an activity, only the installSplashScreen() command before the setContentView command is required in the onCreate method so that the splash screen is available and, after successful display, the theme defined in postSplashScreenTheme is used.

For example, if the initialization of the app takes a long time at startup due to asynchronous I/O calls, it is possible to display the splash screen for a longer time using ViewTreeObserver.OnPreDrawListener.
User-defined programmatic adjustments for animations, for example after the end of the splash screen, are currently only visible from Android 12 and higher.

Overall, the alpha version of this lean API ran without any problems on Android 12 devices, but minor bugs were found in the displays on devices below Android 12, which are to be expected with an early alpha version. We therefore advise against productive use of the API, which is likely to change. Many developers will be grateful for a stable version of this API. Users have seen one or two splash screens in previous apps and can expect this to become standard in the future.

Blur effects and more with the RenderEffect API

As of Android 12, it is much easier to integrate blurs, color filters and other graphic effects in the desired views with the RenderEffect API.

A combination of the respective effects as a chain chain is also possible. The RenderEffect API works efficiently by using the existing rendering pipeline to minimize unnecessary additional calculations.

A blur effect with individual strength can be created on a desired view such as an ImageView or ParentLayout with just one line of code:

view.setRenderEffect(RenderEffect.createBlurEffect(radiusX, radiusY, SHADER_TILE_MODE))

Even less code is required to set the view back to its original state using the following command:

view.setRenderEffect(null)

In previous versions of Android, to achieve the same effect, you would have to request the bitmap information for the content of an ImageView, edit the image accordingly, then create a new bitmap and then put it back into the ImageView.

The biggest disadvantage of this API is the support from Android 12, so a fallback solution would have to be installed on older versions.

Rounded Corner APIs

The Rounded Corner APIs introduced in Android 12 are a response to the ever-increasing proliferation of end devices with rounded corners. The problem developers faced with rounded-corner devices was the potential for UI elements to be separated on the screen.

The Rounded Corner APIs can be used to query information about the presence of rounded corners, including the radius and center point of a rounded corner. Based on this information, the layout of the UI elements can be adjusted according to the end device.

Rich content insertion

With the Unified API, the developer now has a unified API to share content between different applications. Previously there were three different APIs to insert content, for example via the long press menu, via drag-and-drop or from the keyboard.

To be able to use the API, only the listener interface, which has only one method, must be implemented. A big advantage here is the backward compatibility with older Android versions by using the AndroidX Core library from version 1.5.0. Unifying these APIs will significantly improve code quality and aesthetics.

A big advantage here is the backwards compatibility with older Android versions through the use of the AndroidX Core library from version 1.5.0, see https://developer.android.com/jetpack/androidx/releases/core

Overscroll Effect

Starting with Android 12, the visual behavior changes during an overscroll situation. While for versions below Android 12 the end of a list started to glow when there was an overscroll, from Android 12 the individual list elements stretch out depending on the depth of the drag/fling event and bounce back. The user experience is enhanced by the more sophisticated and modern animation and can be used by a developer with the help of the EdgeEffect (see (https://developer.android.com/reference/android/widget/EdgeEffect) within the following classes on all commonly used list, scroll and swipe elements:

• ViewPager2
• ScrollView
• ViewPager
• RecyclerView
• NestedScrollView
• ListView
• HorizontalScrollView
• ScrollView

Overscroll effect in Android 11
Overscroll effect in Android 12

Conclusion

In addition to many visual innovations, important and well-thought-out features have been made available in the areas of user experience, security, and privacy, which will make it palatable for end users to switch to the new Android version.

The changeover will also bring a lot of joy for developers, since most of the features bring with them many simplifications in addition to some innovations.

Unfortunately, not all new features are backwards compatible, which is why backwards compatibility must be written manually for some of the new features, or they are simply not offered for lower Android versions.

See Part 2, Technical features in Android 12 — For Developers. Important changes in related to performance, security, and privacy: https://medium.com/@FrederickKlyk/security-in-android-12-for-developers-60d980a432ac

References

https://android-developers.googleblog.com/2021/03/android-12-developer-preview-2.html

https://blog.google/products/android/android-12-beta

https://android-developers.googleblog.com/2021/05/whats-new-in-android-12-beta.html

https://proandroiddev.com/review-of-android-12-for-developers-ea3ce9247e0

--

--

Frederick Klyk

Software Architect, Senior Android Developer & team leader @ adesso mobile solutions, Twitter: https://twitter.com/frederickklyk