Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

Android Widget Not Updating

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).

Configuration:

<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>`

Manifest Excerpt:

<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>

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.

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.

question from:https://stackoverflow.com/questions/2078122/android-widget-not-updating

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...