Even I am facing a similar issue with lists in appwidgets. And I haven't been able to find a solution till now. I tried using the notifyAppWidgetViewDataChanged(). This has fixed a few cases of the list not getting refreshed. But I am still getting the issue randomly.
On Jul 28, 4:35 pm, Brad <[email protected]> wrote: > I am developing an appwidget for 3.x and I have run into a roadblock. > I would like to manually update an appwidget that contains a list by > pressing a "refresh" button on the appwidget. I am unable to manually > update the content of my appwidget because it appears that the > AppWidgetManager does not push my updates to the home screen promptly, > rather it waits until the ListView is scrolled to constructed apply > the new RemoteView. Here is the relevant code: > > MyAppWidgetProvider extends AppWidgetProvider { > .... > @Override > public void onReceive(Context context, Intent intent) { > > if(intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE)) > { > AppWidgetManager mgr = AppWidgetManager.getInstance(context); > int appWidgetId = > intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID); > > // create the RemoteView > Intent serviceIntent = new Intent(mContext, > MyAppWidgetService.class); > serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, > appWidgetId); > > RemoteViews appWidget = new > RemoteViews(context.getPackageName(), > R.layout.appwidget_widget_layout); > > // set the listener for my configuration activity > Intent configureAction = new Intent(mContext, > MyAppWidgetConfigure.class); > configureAction.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, > appWidgetId); > PendingIntent configurePendingIntent = > PendingIntent.getActivity(mContext, 0, configureAction, > Intent.FLAG_ACTIVITY_NEW_TASK); > > appWidget.setOnClickPendingIntent(R.id.appwidget_configure_widget_button, > configurePendingIntent); > > appWidget.setRemoteAdapter(appWidgetId, > R.id.appwidget_flight_list, serviceIntent); > mgr.updateAppWidget(appWidgetId, appWidget); > } > } > > } > > MyAppWidgetService extends RemoteViewsService { > @Override > public RemoteViewsFactory onGetViewFactory(Intent intent) { > return(new MyRemoteViewsFactory(this.getApplicationContext(), > intent)); > } > > public class MyRemoteViewsFactory implements > RemoteViewsService.RemoteViewsFactory { > …. > …. > // this contains all of the code for downloading the proper data > for the list, etc... > } > > } > > Here is my problem: my configure activity (which just so happens to be > the same activity that is launched when the appwidget is first > created, by placing it in the xml metadata object) broadcasts the > ACTION_APPWIDGET_UPDATE intent, which is received by > MyAppWidgetProvider correctly. The mgr.updateAppWidget() method gets > executed (I have confirmed by placing log statements on either side), > yet for some reason the widget does not get updated on the home screen > promptly. Instead, it will update only if I scroll the ListView and it > needs to grab new rows, then the MyWidgetService gets constructed and > applied to the widget (with the correctly updated data that I intended > it to have). > > So, after scouring the documentation/web for days this seems like the > correct usage. Unfortunately, the app widget does not update as I > would like. What am I doing wrong? Thanks for any help, in advance. I > would love to talk about this problem and share more code if need be. > I just want to figure out this problem! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

