Home » Android » Android widget update frequency 0, what it actually means?

Android widget update frequency 0, what it actually means?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have found the following parts of code in a widget:

<appwidget-provider>
    android:updatePeriodMillis="0"
<appwidget-provider/>

Now, my question is now that: what it does mean with updatePeriodMillis set to 0.

I know that it is set for the how often the widget will receive remoteview or others. so, what is the significance to set it to 0.

How to&Answers:

According to android documentation:

The updatePeriodMillis attribute defines how often the App Widget framework should request an update from the AppWidgetProvider by calling the onUpdate() callback method. The actual update is not guaranteed to occur exactly on time with this value and we suggest updating as infrequently as possible—perhaps no more than once an hour to conserve the battery. You might also allow the user to adjust the frequency in a configuration—some people might want a stock ticker to update every 15 minutes, or maybe only four times a day.

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

Answer:

When you Set updatePeriodMillis to 0, You are actually disabling the update period on that particular widget. Means, that property is no more applicable to that widget.

Answer:

According to Android developers
How often, in milliseconds, that this AppWidget wants to be updated. The AppWidget manager may place a limit on how often a AppWidget is updated.

This field corresponds to the android:updatePeriodMillis attribute in the AppWidget meta-data file.

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