Android 小部件 onUpdate() 问题
我的应用程序中有一个小部件,每次我安装/删除/更新第三个时,它都会搞砸(它的资源之一,一个计数器,只有大于 0 时才可见,并且它不再对按下做出反应)派对应用程序,因为 onUpdate() 方法可能被调用,并且我编写的代码未正确执行。
可以肯定的是,AppWidgetManager 对以下意图做出反应:
android.intent.action.PACKAGE_ADDED
android.intent.action.PACKAGE_REMOVED
android.intent.action.PACKAGE_RESTARTED
但是如何使小部件不对此类意图做出反应,它甚至没有在清单中注册它们?
I have a widget in my app and it gets screwed up (one of it's resources, a counter, has to be visible only if greater than 0 and it does not react anymore to a press) every time I install/remove/update a 3rd party app because the onUpdate() method probably gets called and the code I have written is not executed properly.
It is certain that the AppWidgetManager reacts to the following intents:
android.intent.action.PACKAGE_ADDED
android.intent.action.PACKAGE_REMOVED
android.intent.action.PACKAGE_RESTARTED
But how can I make the widget not react to such intents, it is not even registered for them in the manifest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将这些操作添加到清单中..并避免在 onReceive 方法中对它们做出反应,这在某种程度上是微不足道的解决方案,但它会做!
try adding those actions to the manifest .. and avoid reacting to them in the
onReceive
method, it's somehow trivial solution but it will do !您是否尝试过重写 onReceive 方法并检查意图?我提供了一个简单的例子。
这应该允许您检查传入的意图并过滤掉您不想要的内容
Have you tried overriding the onReceive method and check for the intent? I have provided a quick example.
This should allow you to check the incoming intent and filter out what you don't want