I would like to update my widget every time it gets resized.
Cool!
I figured out that this is done in onAppWidgetOptionsChanged()
More accurately, if you have the right actions in your <intent-filter>
, on Android 4.1+ devices, you will find out about resize events via onAppWidgetOptionsChanged()
.
But I can't find out how to update the widget in it.
You update it the same way you update it in onUpdate()
. Call updateAppWidget()
on the AppWidgetManager
with an appropriate RemoteViews
.
I tried to redraw the widget by calling everything that I put in onUpdate(), but it's not working.
"it's not working" is not a particularly effective description of your symptoms.
How can I make use of the bundle?
For a Bundle
named newOptions
, you can find out your new size range via:
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)
For example, this sample project contains an AppWidgetProvider
that simply pours those values into a string and uses that to update a TextView
. The result looks like:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…