Is it possible to update a widget from an Activity? - Android Developers | Google Groups - 0 views
-
An AppWidgetProvider is a BroadcastReceiver. That gives you two possibilities right off the bat: 1. Have it also handle whatever other Intents you were planning on setting up with a separate BroadcastReceiver, or 2. Send an Intent from whatever component you want to the AppWidgetProvider. In other words, don't worry about trying to talk directly to the app widget (which I suspect is impossible) -- just talk to your code that already talks to the app widget.
-
Vincent Tsao on 13 Jul 10good explanation
-
-
I update my widget from within my app, when I delete/add entries to a list. To do this, I have a method (updateWidget) and a static String (UPDATE_ACTION). My updateWidget() method sends a broadcast which is received by the widget class and then calls onUpdate() with the appropriate params: private void updateWidget() { Intent i = new Intent(this, TVWidget.class); i.setAction(TVWidget.UPDATE_ACTION); sendBroadcast(i); } In TVWidget class: @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action != null && action.equals(UPDATE_ACTION)) { final AppWidgetManager manager = AppWidgetManager.getInstance (context); onUpdate(context, manager, manager.getAppWidgetIds(new ComponentName( context, TVWidget.class) ) ); } else { super.onReceive(context, intent); } } This seems to work fine.