How to remove widget when the app is uninstalled in Android? [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-19 02:39:49

问题


Possible Duplicate:
Removing Widget from Home Screen when Uninstalled

In Android, I have created a widget for my application. When I uninstall the app, the widget shows "problem loading widget" error in home screen. I need a scenario where widget should be removed by the developer through code (and not by the drag and drop to the trash) when I uninstall the app. Is it possible? If so, what changes we need to do? Is there anything that can be set in the manifest so that it removes all references of the app once it is uninstalled?


回答1:


Hiya! When you delete the app widget host manager should broadcast one of the following intents... ACTION_APPWIDGET_UPDATE ACTION_APPWIDGET_DELETED ACTION_APPWIDGET_ENABLED ACTION_APPWIDGET_DISABLED

To make use of this, in your appwidget provider class (or your custom extension of broadcast receiver) receive the broadcast (or use onDeleted() in the appwidgetprovider class) and delete from the application widget host manager the widget with the id of your widget....

Hope this helps...




回答2:


It is not possible to get control when your app is uninstalled. I think Android 2.2 may do a better job of automatically getting rid of your app widget.



来源:https://stackoverflow.com/questions/3387742/how-to-remove-widget-when-the-app-is-uninstalled-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!