如何获得应用程序小部件自己的 ID?

发布于 2024-09-12 14:16:52 字数 258 浏览 4 评论 0原文

我正在尝试调试一个问题,其中我的小部件变得无效并填充了新的小部件。这种情况仅在开始时发生一次,然后它永远保留为第二个小部件。所以,我想输入代码来缩小它发生的时间点。我想做的是这样的:

e.g., (not real code) Log.d(TAG, "myWidgetId=" + this.getMyWidgetId());

然后我会得到所有启用的 ID 的列表,并查看我是否在列表中。我找不到可以给我 ID 的方法、成员、属性等?

I am trying to debug a problem where my widget becomes invalid and a new one fills in. This only happens once at the beginning of time and then it remains the second widget forever. So, I want to put code in to narrow down the point in time when it happens. What I would like to do it something like this:

e.g., (not real code) Log.d(TAG, "myWidgetId=" + this.getMyWidgetId());

Then I would get a list of all the enabled IDs and see if I am in the list. I cannot find a method, member, attribute, etc. that would give me my id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍风燃霜 2024-09-19 14:16:52

这是不可能的。 AppWidgetProvider 的 ID 是隐式处理的并且可以更改,因此,最好的做法是要求 AppWidgetManager 为特定组件生成一个小部件列表,调用它们,然后使用提供的 ID 响应服务请求。

It cannot be done. The AppWidgetProvider's ID is implicitly handled and can change, therefore, the best one can do is to ask the AppWidgetManager to generate a list of the widgets for a particular component, invoke them, then respond to the service request using the provided ID.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文