问题描述
情景1:
- 设备装载
- 在我第一次添加窗口小部件
- Onex公司 - >呼叫onEnabled | 的Galaxy Tab - >犯规通话onEnabled 。
- Device is loaded
- I add first widget
- OneX -> Calls onEnabled | Galaxy Tab -> doesnt call onEnabled.
方案2:
- 在设备启动时与小部件已经在屏幕上。
- Onex公司 - >呼叫onEnabled | 的Galaxy Tab - >通话onEnabled
- Device is booted with widget already on screen.
- OneX -> Calls onEnabled | Galaxy Tab -> Calls onEnabled
但是,当用户把一个在屏幕上(方案1),否则什么点必须被调用。当然,你不必重新启动设备得到onEnabled调用。
But It must be called when user places one on screen (scenario 1), else whats the point. Surely you dont have to restart your device to get onEnabled called.
其重要,因为我附加报警管理器更新我的窗口小部件每2秒:
Its important, because I Attach a alarm manager to update my widget every 2 seconds:
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 1);
alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), 1000, createClockTickIntent(context));
有没有可行的解决方案类似的问题:AppWidgetProvider:不叫onEnabled方法
无需注册这些意图,反正这样犯规的帮助。
There is no need to register these intents, and doing so doesnt help anyway.
我的问题是为什么onEnabled不调用,以及如何得到它。
My question is why is onEnabled not invoking, and how do I get it to.
报告说,在谷歌文档: ACTION_APPWIDGET_ENABLED:
It says on google Docs: ACTION_APPWIDGET_ENABLED:
当一个AppWidget的一个实例添加到主机用于第一发送 时间。该广播发送的引导时,如果有一个AppWidgetHost 与此提供一个实例安装。
基本上确认它应该在这两种情况下
Basically confirming that it should work in both scenarios
这是触发的意图 onEnabled()
调用响应于所述ACTION_APPWIDGET_ENABLED广播时 一个AppWidget此提供程序实例化。覆盖此方法 实现自己的AppWidget功能。
它的工作原理在手机上,而不是平板电脑,事实是奇怪。它是一个问题,与Android 3.2,是有周围的工作?
The fact it works on the phone, and not the tablet, is strange. Is it an issue with android 3.2 and is there a work around?
推荐答案
在很多尝试找到它为什么演戏这条路,我短了。
After lots of attempt to find why it is acting this way, I came up short.
这可以是一个Android相关的问题或设备相关的问题,其中小部件设置了广播永远不会发送。
It is either an android related problem or a device related problem, where the widget enabled broadcast is never sent.
唯一的变通,以获得小部件更新报警经理,是initalise从它自己的方法报警管理器,然后调用从 onEnabled
和的onupdate
。因此,当它达不到 onEnabled
中,它将被的onupdate
被覆盖,当小部件变为自我更新(上应用程序调用它)。而在场景 onEnabled
工作,它只是一个新的实例来替换现有的报警管理器时曾经OnUpdate中被调用。
The only work around to get the widget updating with alarm manager, was to initalise the alarm manager from its own method, and then call that from onEnabled
AND onUpdate
. So when it falls short of onEnabled
, it will be covered by onUpdate
, when the widget goes to update itself (on app call to it). And in the scenario onEnabled
does work, it will just replace the existing alarm manager with a new instance when ever onUpdate is called.
也许不是取决于你正在努力做什么,在onEnabled,但唯一一个我可以找到理想的解决方案。
Maybe not the ideal solution depending on what you are trying to do in onEnabled, but the only one I could find.
这篇关于Android的appWidgetProvider onEnabled从来没有所谓的平板电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!