I'm using Jetpack Glance for making widgets, they are in my case composable. However, I'm completely lost on how to update them.
Let's start with my specific dependency, just to be clear:
implementation "androidx.glance:glance-appwidget:1.0.0-alpha05"
As for the example widget, which displays fine:
class ExampleWidget(private val str: String) : GlanceAppWidget() {
@Composable
override fun Content() {
val customTextStyle = TextStyle(
fontWeight = FontWeight.Bold,
fontSize = 18.sp
)
//WaterWidgetCounter()
Text(str, GlanceModifier, style = customTextStyle)
}
}
This is how I initialize the widget:
class ExampleWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget: GlanceAppWidget = ExampleWidget(LocalDateTime.now().toString())
}
Now I have the working function getRandomString()
, which should override the string the composable widget.
I want to know how to update the text in the widget, when
- resizing the widget.
- tapping on the widget.
- after some minutes randomly.
I have tried using override fun onUpdate
, but this doesn't work at all. How can I make my widget update? The timestamp is never overwritten and it never vanishes.
I'd love to receive some help, given that this technology is very recent and I can't find a lot of good sources on the internet. Thank you in advance.