Update AppWidget from within program?
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"开发者_JAVA技巧));
new WidgetProvider().onUpdate(this, manager, a);
When I call this code, however, a
is empty. What am I doing wrong?
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);
精彩评论