问题
I want to define multiple size widgets I have sees in other questions that a common practice is to define multiple receivers and providers, however in the onUpdate
method I have noticed that there is an array named appWidgetIds
eg
public void onUpdate(Context c, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
.....
....
}
}
so I'm wondering what is the purpose of this array and if could be used for define multiple size widget without create different providers and receivers.
Note that my different size widget use the same design with the difference that in smaller widgets some elements are missing, for this reason a way to avoid to define multiple providers that do almost the same things is welcome.
回答1:
The array is in case they put multiple instances of the widget, so they can all be updated. Most of the time you call the same update code on all widget id's, but this allows you to pick different actions such as if your app has multiple accounts on it, they can have different widgets.
Sizes are specified with the receivers as described in older apis, while newer ones are capable of resizing.
来源:https://stackoverflow.com/questions/25397265/appwidgetids-and-best-way-to-define-multiple-size-or-resizable-widget