从主屏幕动态删除Android小部件
在我从配置活动中按back键后,我需要删除一个主屏幕小部件实例,因为我希望它被完全删除,而不是因为配置活动而处于“边缘”。因此,这将是一个很好的修复方法:从主屏幕动态删除Android小部件,android,android-widget,Android,Android Widget,在我从配置活动中按back键后,我需要删除一个主屏幕小部件实例,因为我希望它被完全删除,而不是因为配置活动而处于“边缘”。因此,这将是一个很好的修复方法: 修复2539问题,让小部件实例优雅地从主屏幕和“边缘”中消失 让程序员通过AppWidgetHost使用指向主屏幕的正确id来实现这一点(使此安全漏洞得到验证)。(描述了有趣的尝试) 现在这些都是可能的吗?我自己解决,只处理两个布尔标志。 下面是我在扩展AppWidgetProvider的类上所做的 public void onUpdate(
现在这些都是可能的吗?我自己解决,只处理两个布尔标志。 下面是我在扩展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);
}
}
}
链接似乎断了