Skip to content

Instantly share code, notes, and snippets.

@kasem-sm
Last active June 1, 2022 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasem-sm/6376cd6b42405c90c8d6e6c2b45eb2e8 to your computer and use it in GitHub Desktop.
Save kasem-sm/6376cd6b42405c90c8d6e6c2b45eb2e8 to your computer and use it in GitHub Desktop.
When Jetpack's Glance met his fellow worker, Work Manager
suspend fun updateWidget(articleTitle: String, context: Context) {
// Iterate through all the available glance id's.
GlanceAppWidgetManager(context).getGlanceIds(MyWidget::class.java).forEach { glanceId ->
updateAppWidgetState(context, glanceId) { prefs ->
prefs[stringPreferencesKey("article_title_key")] = articleTitle //new value
}
}
MyWidget().updateAll(context)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment