我需要在从配置 Activity 中按回后删除一个主屏幕小部件实例,因为我希望它被完全删除,而不是因为 issue 2539 而留在“边缘”。 .因此,这些修复之一会很好:
- 修复问题 2539,让小部件实例从主屏幕和“limbo”中优雅地消失
- 让程序员通过具有指向主屏幕的正确 ID 的 AppWidgetHost 执行此操作(证明此安全漏洞)。 (有趣的尝试描述了 here )
现在这些有可能吗?
最佳答案
我自己解决了,只处理了两个 bool 标志。 这是我在扩展 AppWidgetProvider 的类上所做的
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
SharedPreferences settings = context.getSharedPreferences(SHARED_PREFERENCES, 0);
for(int widgetId:appWidgetIds)
{
boolean configured = settings.getBoolean(CONFIGURED_PREFERENCE+widgetId, false); //In order to skip initial UpdateService
boolean widget= settings.getBoolean(WIDGET_PREFERENCE+widgetId, false);
if(!widget && configured) continue; // In order to skip phantom Widgets update
if(!configured)
{
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(CONFIGURED_PREFERENCE+widgetId, true);
editor.commit();
}
else
{ Intent updateService=new Intent(context, UpdateService.class);
updateService.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,widgetId);
context.startService(updateService);
}
}
}
关于android - 从主屏幕动态删除 Android Widget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8307270/