Reputation:
I would like to update my widget every time it gets resized. I figured out that this is done in:
onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions)
But I can't find out how to update the widget in it. I tried to redraw the widget by calling everything that I put in onUpdate()
, but it's not working. How can I make use of the bundle?
Upvotes: 17
Views: 9472
Reputation: 1006654
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:
Upvotes: 33