3

I'm searching for the best way to back up the current state of my app widget. I've got a bitmap and I remember its timestamp:

private data class TimestampedBitmap(val bitmap : Bitmap, val timestamp : Long)

private var tsBitmap: TimestampedBitmap? = null

However, if my app gets killed-restarted, i lose my tsBitmap instance. I want to avoid having to reload this data from the network (there may be no network connection to begin with) and I'm looking for the most elegant approach to achieve it.

I studied the documentation for AppWidgetProvider.onUpdate():

Called in response to the AppWidgetManager.ACTION_APPWIDGET_UPDATE and AppWidgetManager.ACTION_APPWIDGET_RESTORED broadcasts when this AppWidget provider is being asked to provide RemoteViews for a set of AppWidgets.

The second event type sounds interesting. This is what the official docs have to say:

String ACTION_APPWIDGET_RESTORED

Sent to an AppWidgetProvider after AppWidget state related to that provider has been restored from backup. The intent contains information about how to translate AppWidget ids from the restored data to their new equivalents.

What, technically speaking, is the "state related to that provider"? Can I make TimestampedBitmap become a part of that state? I realize that this event type is about restoring from a backup only at the time the app is (re)installed, but I still wonder whether the kind of state it talks about is the one that I should be using?

Community
  • 1
  • 1
Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436

0 Answers0