Google releases Jetpack Glance Alpha for super-easy widget development
Jetpack Compose makes it possible to create interfaces for Android apps without dealing with lengthy XML files and other clunky resources. Instead, it allows developers to create interface elements in Kotlin code (alongside the rest of the app’s code), with simpler APIs and full Material Design support. Now Google is bringing that same ease of use to widgets, with the introduction of Jetpack Glance Alpha.
Google wrote in an announcement, “Android 12 revamps a key feature for many Android users, App Widgets, making them more useful, beautiful, and discoverable (84% use at least 1 widget). Today, we’re making it even easier to build them by releasing the first alpha of Jetpack Glance, a new framework built on top of the Jetpack Compose runtime designed to make it faster and easier to build app widgets for the home screen and other surfaces.”
Jetpack Glance allows app developers to create widgets with similar declarative Kotlin-based APIs as Jetpack Compose. This first alpha build includes an initial set of Glance Composables (Box, Row, Column, Text, Button, LazyColumn, Image, Spacer), a few predefined actions (actionStartActivity, actionRunCallback, etc.), and interoperability with existing RemoteViews.
Jetpack Glance was mentioned at the Android Dev Summit back in October, but now it’s actually available for developers to try. There’s a code sample on GitHub, and Glance is compatible with the latest stable build of Android Studio.
Google has rolled out several other improvements for Jetpack Compose in recent months. Support for Material You and Wear OS arrived in October, Compose for creating Android Auto apps was released in March, and Jetpack Compose itself left the beta stage in July. There’s also work underway to bring Jetpack Compose to the web, which would allow an app with a single codebase to run across, Android, macOS, Windows, Linux, and web browsers.