从主屏幕动态删除Android Widget

问题描述:

我从配置活动中按下后需要删除主屏幕Widget实例,因为我希望将其完全删除,并且不会因此而留在“边框”中issue 2539。因此,这将是所有这些修复好的一个:从主屏幕动态删除Android Widget

  1. 修复问题2539,并让控件实例优雅无论是从主屏幕,并从“地狱”
  2. 让程序员做到这一点线槽AppWidgetHost用正确的ID指的消失不见主屏幕,(使这个安全漏洞证明)。 (有趣的尝试描述here

现在是任何这些可能吗?

我自己解决,只处理两个布尔标志。 这里是我做了延长的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); 
    } 


    } 

} 

对于一个完整的交代类我写的整个过程on my blog