views:

83

answers:

1

I need to update my AppWidget when my main activity pauses. I tried using the following code in my main activity's onPause():

super.onPause();
AppWidgetManager manager = AppWidgetManager.getInstance(this);
int[] a = manager.getAppWidgetIds(new ComponentName(this, "WidgetProvider"));
new WidgetProvider().onUpdate(this, manager, a);

When I call this code, however, a is empty. What am I doing wrong?

A: 

I use this code to update my AppWidget:

AppWidgetManager manager = AppWidgetManager.getInstance(this);
int[] a = manager.getAppWidgetIds(new ComponentName("my.pkg", "WidgetProvider"));
List<AppWidgetProviderInfo> b = manager.getInstalledProviders();
for (AppWidgetProviderInfo i : b) {
    if (i.provider.getPackageName().endsWith("pkg")) {
        a = manager.getAppWidgetIds(i.provider);
    }
}
new WidgetProvider().onUpdate(this, manager, a);
Matt