glance-appwidget-updates-and-memory
What it does
This skill guides updating Android home screen widgets built with Jetpack Glance or RemoteViews. It covers refreshing stale or frozen widget content and keeping images within Android 17 memory limits. It is for Android developers who maintain app widgets.
When to use it
- ✓When a Glance widget on the home screen shows old or frozen content after a background sync.
- ✓When you set up an Android 17 widget and need to keep its images within the memory limit.
- ✓When you maintain a classic AppWidgetProvider and want to update it correctly.
Skill link
https://github.com/android/skills/blob/main/system/glance-appwidget-updates-and-memory/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“My Glance widget stops updating after the background sync. Fix the refresh and keep the images small.”
5 new skills a week. 1 minute to read.
How it works
The skill checks your build and manifest settings, then downsamples images to the widget's size. It also updates the widget state so the home screen shows the latest content.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
This skill provides guidance for managing state updates and keeping Android
AppWidgets that use Jetpack Glance (androidx.glance:glance-appwidget) or
RemoteViews within the Android 17 widget bitmap memory limits. For widget UI
layout templates, suggest the glance-canonical-layouts skill.
- When configuring a Glance widget, see Create an app widget with Glance.
- When targeting Android 17 (
targetSdk = 37), see Android 17 widget memory limits. - When maintaining a classic
AppWidgetProvider, see Create an app widget.
Prerequisites
- Kotlin Android project (
minSdk >= 26) withcompileSdk = 37(targetSdk = 37when targeting Android 17) inbuild.gradle.kts. - Jetpack Glance (
1.2.0, minimum1.1.1+) and the Compose compiler Gradle plugin enabled on the module.
Critical mandates
- Preserve existing package name and toolchain versions : Inspect
build.gradle.kts,gradle/libs.versions.toml, and Kotlin files first. Keep existingnamespace,applicationId,package,targetSdk(unless migrating to Android 17), Android Gradle Plugin (AGP), and Kotlin versions. - Downsample images to widget dimensions and estimate the memory cap : Android
system_servercomputes theRemoteViewsbitmap memory cap (6 * width * heightbytes, or1.5 * 4 * width * height) once at boot from the real size of the default display and does not expose this cap in a public API. Because unfolding a foldable or switching display resolution toQHD+after boot can make active window metrics report a larger value than the boot-time cap, always downsample each image first to the widget's target dimensions (maxWidthDp x maxHeightDpinRGB_565orALPHA_8), and enforce the per-image byte ceiling (calculateWidgetMemoryCapBytes(context) / distinctImageCount) estimated as6 * width * heightfromWindowManager.currentWindowMetrics.boundson API 30+ (falling back toresources.displayMetricson API 26-29 or ifWindowManageris unavailable). - Decode shared bitmaps once outside provideContent : Both
SizeMode.Exact(used byglance-canonical-layoutsto compose the current span's portrait and landscape orientations) andSizeMode.Responsive(used to pre-bundle a set ofDpSizebreakpoints) invokeprovideContentmultiple times per update. Decode shared bitmaps once inprovideGlancebeforeprovideContentand pass them toImageProvider(bitmap)soRemoteViewsdeduplicates the sharedBitmapacross all sizes in either mode. If a widget scales distinct bitmaps perLocalSize.current, dividecalculateWidgetMemoryCapBytes(context)by the number of distinct bitmaps. - Downsample content URIs and grant launcher read permissions : On Android 17 (
targetSdk >= 37), bitmap-backedIcons count toward the cap alongsideBitmaps.content://URIs passed toImageProvider(uri)orRemoteViews.setImageViewUridon't count toward the inter-process communication (IPC) cap, but the launcher decodes them at full resolution. Downsample the file intocontext.cacheDir, expose it withFileProvider.getUriForFile, and grantIntent.FLAG_GRANT_READ_URI_PERMISSIONtoIntent.CATEGORY_HOMEpackages. - Trigger explicit widget updates after state mutations :
updateAppWidgetStatewrites preferences to DataStore without updating the widget UI. After you mutate state, callGlanceAppWidget.update(context, glanceId)orGlanceAppWidget.updateAll(context). - Use full updateAppWidget calls when you replace images : In
AppWidgetProviderclasses, when you replace bitmaps orIcons, callAppWidgetManager.updateAppWidgetinstead ofpartiallyUpdateAppWidget.
Reference implementation files
Read the companion reference files in references/ when implementing each step,
and update the sample package declaration and class names to match your app:
- Bitmap Cap & FileProvider Helper : WidgetBitmapUtils.kt
- Responsive Widget, Receiver & Error Fallback : SampleGlanceWidget.kt
- LazyColumn Collection Widget & Revision Cache : FeedCollectionGlanceWidget.kt
- DataStore State Push, CoroutineWorker & ActionCallback : [WidgetStateAndActions.kt](references/WidgetStateAndAct
FAQ
What Android version does it target?
It covers Android 17 (API 37) widget memory limits and the settings needed to target that version.
Do I need Glance?
The skill is built for Jetpack Glance widgets, and it also covers classic RemoteViews widgets.
Does it design the widget layout?
Layout templates are handled by a separate canonical layouts skill.
Details
Original description by the author
Manages Android AppWidget state updates, background syncs, and RemoteViews bitmap memory limits with Jetpack Glance (androidx.glance:glance-appwidget) and AppWidgetProvider receivers on Android 17 (API 37). Use this skill when configuring Android 17 (API level 37) compileSdk/targetSdk and AndroidManifest.xml widget receivers, refreshing frozen or stale Glance widget UI after CoroutineWorker DataStore preference updates (updateAppWidgetState), downsampling images within the WindowMetrics memory limit for SizeMode.Responsive, SizeMode.Exact, or LazyColumn, sharing content:// URIs with FileProvid
repo: android/skills
Popularity
- GitHub stars
- 10k
- Ranking position
- #11935
- License
- Apache-2.0
- Updated
- 10/29/2026
Comments
- …
More skills from this repository
agp-9-upgrade
10kHelps your agent upgrade an Android app to Android Gradle Plugin 9 and work through its breaking changes. Not for multiplatform projects.
camerax
10kHelps your agent build Android camera features with CameraX, including video recording, hardware controls, ML Kit and Media3 effects.
android-for-cars-parked-apps
10kHelps your agent adapt an Android video, game or browser app to run as a parked app on Android Auto and Android Automotive.
appfunctions
10kHelps your agent find key workflows in an Android app and expose them as AppFunctions that AI agents and voice commands can run.
Similar skills
android-clean-architecture
280kMakes your agent organize Android projects efficiently. It structures the code to make maintenance and new feature development easier.
compose-multiplatform-patterns
280kHelps your agent use Compose Multiplatform and Jetpack Compose patterns in KMP projects, covering state, navigation, theming, and performance.
dart-flutter-patterns
280kMakes your agent write code for Dart and Flutter apps. It uses modern patterns to create robust and manageable apps.