Home screen widgets with Glance

Modern Android Mid-level Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Pick the fix

A Glance widget uses androidx.compose.material3.Text and crashes when placed. Fix?

Options
Hint 1 of 1

What can the launcher draw?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Use androidx.glance.text.Text and other Glance composables

Correct. Only Glance composables can be translated to RemoteViews.

Why not the others?
  • B Wrap it in a Surface. Still a normal composable.
  • C Add an AndroidView. Not supported in widgets.
  • D Update the Compose BOM. Doesn't change the rule.

30-second answer

Glance lets you write widgets with a Compose-style API. You extend GlanceAppWidget and build UI in provideGlance using Glance composables like Column and Text from the glance packages. Glance translates them into RemoteViews, because widgets run in the launcher's process. Update widgets with update() or from WorkManager, and keep the work small.

Practise saying it · 25 s. No recording, just a timer

Explain Glance widgets.

Say your answer out loud, then check which of these points you covered:

  • Compose-style API
  • Translated to RemoteViews
  • Glance composables only
  • Update limits

Deep dive

Foundation and Material composables don't work in widgets; use Glance ones.

updatePeriodMillis can't refresh more often than every 30 minutes.

Clicks use actions like actionStartActivity or actionRunCallback.

Responsive sizes let one widget adapt to different cell sizes.

Common mistakes

  • Using normal Compose composables in a widget.
  • Frequent network refreshes that drain battery.
  • Heavy work in the receiver.

Senior take & follow-ups

Mention RemoteViews translation and update limits.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why RemoteViews?

    Show hint

    The widget is drawn by the launcher, another process.

  2. How often can a widget auto-update?

    Show hint

    At most every 30 minutes with updatePeriodMillis; use WorkManager or push for more.

Compare on iOS: Building widgets with WidgetKit Both draw outside the app process with a limited UI toolkit.

Suggest a fix if something here is wrong or out of date.