在Android中卸载应用程序时如何删除小部件? [英] How to remove widget when the app is uninstalled in Android?

查看:32
本文介绍了在Android中卸载应用程序时如何删除小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
卸载时从主屏幕删除小部件

在 Android 中,我为我的应用程序创建了一个小部件.当我卸载应用程序时,小部件在主屏幕上显示加载小部件时出现问题"错误.我需要一个场景,当我卸载应用程序时,开发人员应该通过代码(而不是通过拖放到垃圾箱)删除小部件.是否可以?如果是这样,我们需要做哪些改变?是否可以在清单中设置任何内容,以便在卸载后删除应用程序的所有引用?

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?

推荐答案

你好!当您删除应用程序小部件主机管理器应广播以下意图之一...ACTION_APPWIDGET_UPDATEACTION_APPWIDGET_DELETEDACTION_APPWIDGET_ENABLEDACTION_APPWIDGET_DISABLED

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

为了利用这一点,在您的 appwidget 提供程序类(或您的广播接收器的自定义扩展)中接收广播(或在 appwidgetprovider 类中使用 onDeleted())并从应用程序小部件主机管理器中删除具有 id 的小部件你的小部件....

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...

这篇关于在Android中卸载应用程序时如何删除小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆