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
andAppWidgetManager.ACTION_APPWIDGET_RESTORED
broadcasts when thisAppWidget
provider is being asked to provideRemoteViews
for a set ofAppWidget
s.
The second event type sounds interesting. This is what the official docs have to say:
String ACTION_APPWIDGET_RESTORED
Sent to an
AppWidgetProvider
afterAppWidget
state related to that provider has been restored from backup. The intent contains information about how to translateAppWidget
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?