Android AppWidget 在重新启动之前不会显示在蜂窝菜单中
我已经为 Honeycomb 创建了一个 AppWidget,它运行良好,但首次安装时,它不会显示在“Widgets”菜单中,因此无法将其添加到主屏幕。重新启动设备将使其显示,或者在开发过程中,从 Eclipse 发送两次将使其显示。
有什么想法吗?
谢谢!
I have created an AppWidget for Honeycomb which is working well, except that when first installed, it does not show up in the Widgets menu so it can not be added to a home screen. Rebooting the device will allow it to show up, or during development, sending it twice from Eclipse will cause it to show up.
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
显然 EboMike 是对的,设置 android:installLocation="internalOnly" 确实解决了这个问题。如果没有指定安装位置,它应该默认为internalOnly,但似乎不适合我。也许蜂巢发生了一些变化?
另外,即使设置了internalOnly,从 Eclipse 安装时我仍然遇到问题(小部件直到第二次运行才会显示在选择菜单中),但从 android 市场安装时,它似乎工作正常,这是我的专业忧虑。
谢谢!
Appearently EboMike was right, setting android:installLocation="internalOnly" did fix the issue. Without specifying an install location, it should have defaulted to internalOnly, but did not seem to for me. Perhaps something changed in Honeycomb?
Also, even with internalOnly set, I was still seeing the issue when installing from Eclipse (widget would not show up in the selection menu until the second run) but when installing from the android market, it seems to be working fine which was my major concern.
Thanks!
其原因实际上已描述此处,它是从 Android 3.1 开始设计的。默认情况下,installLocation 已设置为“internalOnly”,因此不应解决问题,也不应重新启动。
要解决此问题,需要在您的小部件中触发一个活动。这将激活它,然后它将出现在小部件列表中。
为此,您可以添加一个基本上不执行任何操作的活动:
1)在 AndroidManifest.xml 中,将其添加到“application”标签中:
2)然后在“src”中创建一个“DummyActivity.java”类,如下所示现在
,当您将小部件部署到设备时,该活动将自动启动(您将在 Eclipse 控制台中看到一条消息“正在启动活动...”),并且它将立即“完成”,而不显示任何视觉内容在设备上。现在您的小部件将列在小部件列表中!
The reason for this is actually described here and it is by design as of Android 3.1. By default, the installLocation will already be set to "internalOnly" so that should not fix the problem and neither should a reboot.
To work around this, an activity needs to be triggered in your widget. This will activate it and it will then appear in the widget list.
To do this, you can add an activity that essentially does nothing like this:
1) In your AndroidManifest.xml, add this inside your "application" tag:
2) Then create a "DummyActivity.java" class in your "src" like this:
Now, when you deploy the widget to your device, that activity will be launched automatically (you'll see a message in your Eclipse console saying "starting activity ...") and it will immediately "finish" without showing anything visual on the device. And now your widget will be listed in the widget list!
诡异的是,
我做了这个 installLocation 修复,第一次就成功了。
但从那时起,每次我用 3.01 更新 Xoom 上的小部件时,我仍然需要重新启动才能在列表中看到它。
Spooky,
I did this installLocation fix and it worked first time.
But from then on I still have to reboot every time I update my widget on my Xoom with 3.01 to see it in the list.
为了用我的小部件解决这个问题,我发送小部件更新广播,就像在我的 WidgetController.class 中一样:
然后为了在系统中提供稳定的小部件初始化,我在应用程序或小部件启动时从应用程序对象发送此广播:
!!!重要提示:当 AppWidget 托管在应用程序中时就足够了,但是当 AppWidget 与应用程序分离时,您应该使用本主题中上面@John 提出的方法。
To solve this problem with my widget I send widget update broadcast, like this in my WidgetController.class:
then to provide stable widget initialization in the system I send this broadcast from Application object when application or widget start:
!!! Important: when AppWidget hosts in application it's enough, but when AppWidget separated from it you should use way proposed by @John above in this topic.