Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 408
phogel Avatar asked Jan 16 '10 16:01

phogel


People also ask

Why are my widgets not updating?

Check your internet connectivity Just like apps, most Android widgets need a stable internet connection to work. For example, widgets like weather, news, or Gmail, need to connect to the internet to give you up-to-date data. Make this the first thing you check if you encounter issues with your Android widgets.

Why are my widgets not showing up Android?

The most common reason for a widget to disappear is when Android users transfer applications to a memory card. Widgets may also disappear after the hard reboot of your device. To return it, you need to transfer them again to the phone's memory.

Why are my widgets not working?

It turns out that this is a feature of Android where widgets are blocked for apps that are installed to the SD card. This was my problem since I had just moved all of my apps the SD card to save space.

How do you update widgets?

Full update: Call AppWidgetManager. updateAppWidget(int, android. widget. RemoteViews) to fully update the widget.


2 Answers

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.

like image 163
CommonsWare Avatar answered Sep 22 '22 15:09

CommonsWare


From the SDK:

Note: If the device is asleep when it is time for an update (as defined by updatePeriodMillis), then the device will wake up in order to perform the update. If you don't update more than once per hour, this probably won't cause significant problems for the battery life.

If, however, you need to update more frequently and/or you do not need to update while the device is asleep, then you can instead perform updates based on an alarm that will not wake the device.

To do so, set an alarm with an Intent that your AppWidgetProvider receives, using the AlarmManager. Set the alarm type to either ELAPSED_REALTIME or RTC, which will only deliver the alarm when the device is awake. Then set updatePeriodMillis to zero ("0").

And when SDK 1.6+:

Note: Updates requested with updatePeriodMillis will not be delivered more than once every 30 minutes.

like image 26
duduli Avatar answered Sep 19 '22 15:09

duduli