Android部件不更新 [英] Android Widget Not Updating

查看:146
本文介绍了Android部件不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个简单的小部件显示在主屏幕上。我遇到的问题是,是的OnUpdate只有当我安装部件被调用一次。配置在下面。注:我不会离开的更新周期为20秒,因为我知道会杀死电池(只是测试)

I am trying to implement a simple widget for display on the home screen. The problem I am experiencing is that onUpdate is only being called once when I install the widget. The configuration is below. Note: I will not leave update period at 20 secs as I know that would kill battery (just testing).

配置:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
   android:minWidth="294dp"
   android:minHeight="72dp"
   android:updatePeriodMillis="20000"
   android:initialLayout="@layout/my_custom_app_widget">`
</appwidget-provider>`

清单摘录:

<receiver android:name="MyCustomWidgetProvider">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <meta-data android:name="android.appwidget.provider"
        android:resource="@xml/my_custom_app_widget_info" />
</receiver>

我观察以下行为,当我安装插件: 在我上的onReceive WidgetProvider类被称为然后onEnabled随后的onReceive,然后OnUpdate中。

I am observing the following behavior when I install the widget: In my WidgetProvider class on onReceive is called then onEnabled then onReceive, then onUpdate.

在该部件显示器和OnUpdate中永远不会再次调用。我还检查provder的设置时的onupdate被调用,并在上面的XML(如更新周期)设置的一切是正确的。

After that the widget displays and onUpdate is never called again. I also inspect the settings of the provder when onUpdate is called and everything set in XML above (e.g. update period) is correct.

推荐答案

虽然你有安卓updatePeriodMillis 设置为20秒,最小的实际时间为30分钟。因此,如果您还没有等待30分钟,看看是否有你的测试过程中的更新,则需要等待的时间长一点。

While you have android:updatePeriodMillis set to 20 seconds, the minimum actual time is 30 minutes. So, if you have not been waiting 30 minutes to see if there is an update during your testing, you will need to wait a bit longer.

这篇关于Android部件不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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