Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Widgets: onDataSetChanged not called by updateAppWidget()

I have a ListView-based widget running well, and it relies on a JSON web service call to populate itself. I have a refresh button which works great, and forces a reload from the web. I do it by using a custom broadcast which then calls both onDataSetChanged(), then updateAppWidget() in sequence. What I have found is that when Android updates the widget automatically (based on the time interval set it my XML definition), only updateAppWidget() seems to be called, and my onDataSetChanged() function never runs, leading to an updated timestamp (which I update in each updateAppWidget() call), but stale data.

How can I force Android to call or trigger onDataSetChanged() at a given interval?

like image 302
RealCasually Avatar asked Sep 13 '12 19:09

RealCasually


1 Answers

Turns out I needed to call AppWidgetManager.notifyAppWidgetViewDataChanged(widgetId, view) inside my AppWidgetProvider.onUpdate() method.

like image 59
RealCasually Avatar answered Sep 28 '22 02:09

RealCasually