i'm working on an android widget that fetches content from my api.
What i'm using now is a custom function that uses a callback included in onUpdate => api.getLastItems(MyCallback).
MyWidget provider :
public void onUpdate(Context _context, AppWidgetManager _appWidgetManager,int[] _appWidgetIds) {
api.getLastItems(new requestCallback() {
@Override
public void onFinish(Object object) {
ArrayList<String> announcs_titles = (ArrayList<String>)object;
final int N = widgetId.length;
for (int i = 0; i < N; i++) {
Intent myIntent = new Intent(context, WidgetService.class);
myIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,widgetId[i]);
myIntent.putStringArrayListExtra("itemsTitles",items_titles);
...
appWidgetManager.updateAppWidget(widgetId[i], widget);
}
}
});
super.onUpdate(context, appWidgetManager, widgetId);
}
Because RemoteViewsService.RemoteViewsFactory use a special function getViewAt(int position) that needs a position to begin working, I used this kind of structure to let my widget wait until my ArrayList of Items gets filled.
is that right or there is another method for that? and how could i refresh my widget by a clickEvent (i mean the way to do it, not the PendingIntent.getActivity code)