appWidgetIds and best way to define multiple size (or resizable) widget

落爺英雄遲暮 提交于 2020-02-07 07:14:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!