Android 小部件未更新

Android Widget Not Updating(Android 小部件未更新)
本文介绍了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 小部件未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)