Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically update widget from activity/service/receiver

I know it's possible, but I can't figure out a way to trigger an update of my widget from the main activity. Isn't there some general intent I can broadcast?

like image 970
Nuvious Avatar asked Aug 11 '10 03:08

Nuvious


People also ask

How to update widget in android programmatically?

Full update: Call AppWidgetManager. updateAppWidget(int, android. widget. RemoteViews) to fully update the widget.


1 Answers

If you are using an AppWidgetProvider, you can update it this way:

Intent intent = new Intent(this, MyAppWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID, // since it seems the onUpdate() is only fired on that:  int[] ids = AppWidgetManager.getInstance(getApplication())     .getAppWidgetI‌​ds(new ComponentName(getApplication(), MyAppWidgetProvider.class)); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); sendBroadcast(intent); 
like image 160
phaethon Avatar answered Oct 11 '22 08:10

phaethon