问题描述
我正在尝试实现一个简单的小部件以在主屏幕上显示.我遇到的问题是 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>
我在安装小部件时观察到以下行为:在我的 WidgetProvider 类中调用 onReceive,然后调用 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.当调用 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.
推荐答案
虽然您将 android: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 小部件未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)