Android Widget Not Updating(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>
我在安装小部件时观察到以下行为:在我的 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 小部件未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android 小部件未更新


基础教程推荐
- Android文本颜色不会改变颜色 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01