Slide 42
Slide 42 text
STATE
class CounterIncrementActionCallback : ActionCallback {
override suspend fun onRun(
context: Context,
glanceId: GlanceId,
parameters: ActionParameters
) {
// Get the incremented value from the parameters since
// we are sending it from the composable
val counter = parameters[MyAppWidget.COUNTER_ACTION_PARAMETER_KEY] ?: 0
// Save the counter into the data store
updateAppWidgetState(
context = context,
definition = PreferencesGlanceStateDefinition,
glanceId = glanceId
) {
it.toMutablePreferences().apply {
this[MyAppWidget.COUNTER_KEY] = counter
}
}
// Need to update the widget as well in order
// to invoke the content function again
MyAppWidget().update(context, glanceId)
}
}