In an AppWidgetProvider
class, I have a simple CountDownTimer
running.
object : CountDownTimer(30000, 1000) {
override fun onTick(millisUntilFinished: Long) {
val appWidgetManager = AppWidgetManager.getInstance(context)
val views = RemoteViews(context.packageName,R.layout.view_group)
views.setTextViewText(R.id.m_text_view,"seconds remaining: " + millisUntilFinished / 1000)
appWidgetManager.updateAppWidget(appWidgetIds[0], views)
}
override fun onFinish() {
// Do nothing
}
}.start()
This updates the corresponding widget (appWidgetIds[0]
) as expected, but this is only the case while the app is open. When I swipe off the app in the recents menu, I.e. closing it, the widget stops updating.
I have tried using a separate service too, but same result. Presumably because the service is not a foreground service, and I don't want to have a persistent notification so I can't use a foreground service.