Harsan Valentin
Harsan Valentin

Reputation: 213

Android appwidget onUpdate()

I have a question with the onUpdate function of an android appwidget: I am updating the appwidget once a day with that function. Before this I used a TimerTask class to update the widget but Android sometime closes that TimerTask and my widget stops updating. If I use the onUpdate function the oS will do the same as before or it will work good?

this is the xml that provides the updates:

<?xml version="1.0" encoding="utf-8" ?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="262dp"
android:minHeight="244dp"
android:updatePeriodMillis="86400000"
android:initialLayout="@layout/main"/>

Upvotes: 1

Views: 525

Answers (2)

Yury
Yury

Reputation: 20936

In this case your device will wake up and update widgets. This is written in the documentation.

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.

But to my point of view it's better to use AlarmManager and control the behavior of AppWidgets with flags.

Upvotes: 1

Stefan
Stefan

Reputation: 4705

If your question was "will Android call my widget's onUpdate() method every 86400000 millies?" then the answer is "yes, it will". And it will do so for every instance of your widget independently (how did you manage the widget ID in your service?).

Upvotes: 0

Related Questions