Android的appWidgetProvider onEnabled从来没有所谓的平板电脑 [英] Android appWidgetProvider onEnabled never called on tablet

查看:254
本文介绍了Android的appWidgetProvider onEnabled从来没有所谓的平板电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情景1:

  1. 设备装载
  2. 在我第一次添加窗口小部件
  3. Onex公司 - >呼叫onEnabled | 的Galaxy Tab - >犯规通话onEnabled
  1. Device is loaded
  2. I add first widget
  3. OneX -> Calls onEnabled | Galaxy Tab -> doesnt call onEnabled.

方案2:

  1. 在设备启动时与小部件已经在屏幕上。
  2. Onex公司 - >呼叫onEnabled | 的Galaxy Tab - >通话onEnabled
  1. Device is booted with widget already on screen.
  2. 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));

有没有可行的解决方案类似的问题:<一href="http://stackoverflow.com/questions/5483651/appwidgetprovider-not-called-onenabled-method">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   与此提供一个实例安装。

Sent when an instance of an AppWidget is added to a host for the first time. This broadcast is sent at boot time if there is a AppWidgetHost installed with an instance for this provider.

基本上确认它应该在这两种情况下

Basically confirming that it should work in both scenarios

这是触发的意图 onEnabled()

调用响应于所述ACTION_APPWIDGET_ENABLED广播时   一个AppWidget此提供程序实例化。覆盖此方法   实现自己的AppWidget功能。

Called in response to the ACTION_APPWIDGET_ENABLED broadcast when the a AppWidget for this provider is instantiated. Override this method to implement your own AppWidget functionality.

它的工作原理在手机上,而不是平板电脑,事实是奇怪。它是一个问题,与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从来没有所谓的平板电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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