Blog Infos
Author
Published
Topics
,
Published
How does it work?
class HelloWorldWidget: GlanceAppWidget() {
@Composable
override fun Content() {
Text(text = "Hello world!")
}
}
class HelloWorldWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget = HelloWorldWidget()
}
It uses its own Compose implementation

Glance App Widget Error example

And a similar stack trace on Logcat:

E/GlanceAppWidget: Error in Glance App Widget
java.lang.IllegalStateException: CompositionLocal LocalDensity not present at androidx.compose.ui.platform.CompositionLocalsKt.noLocalProvidedFor(CompositionLocals.kt:170)
Updating is different from Jetpack Compose

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

, ,

Building Modern Responsive Widgets with Jetpack Glance

In this lightning talk, we’ll explore how to get started with building responsive widgets using Jetpack Glance, a modern toolkit designed to simplify and enhance the widget development experience on Android.
Watch Video

Building Modern Responsive Widgets with Jetpack Glance

Jonathan Petit-Frere
Software Engineer,
Android at Netflix

Building Modern Responsive Widgets with Jetpack Glance

Jonathan Petit-Fre ...
Software Engineer,
Android at Netflix

Building Modern Responsive Widgets with Jetpack Glance

Jonathan Petit-F ...
Software Engineer,
Android at Netflix

Jobs

No results found.

User interactions are easier to handle
Button(
text = "Home",
modifier = GlanceModifier.clickable(actionStartActivity<HomeActivity>())
)

It is also possible to create custom actions to better fit your user experience needs:

Button(
text = "Update",
modifier = GlanceModifier.clickable(actionRunCallback<UpdateAction>())
)
class UpdateAction : ActionCallback {
override suspend fun onRun(context: Context, glanceId: GlanceId, parameters: ActionParameters) {
// Update!
}
}
Make sure to test on Android 12 and below
What’s next?

Alkaa Task List Widget

Last December, Google announced the alpha version of Jetpack Glance library for making App Widgets. This new tools allow us to use Jetpack Compose like style, making it faster and easier to create expressive and responsible widgets for our application.

 

Thanks to Marcel Pintó and Bruno Kenji Tiba.

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
It’s one of the common UX across apps to provide swipe to dismiss so…
READ MORE
blog
In this part of our series on introducing Jetpack Compose into an existing project,…
READ MORE
blog
In the world of Jetpack Compose, where designing reusable and customizable UI components is…
READ MORE
blog

How to animate BottomSheet content using Jetpack Compose

Early this year I started a new pet project for listening to random radio…
READ MORE
Menu