Question

I have a requirement where in i need to updated my widget once in every 15 seconds. There is a method called android:updatePeriodMillis but that seems to be getting fired only after 30 minutes.

I took an approach of updating my Widget with the help of AlarmManager. The widget updates but the issue is it slows down the performance of the device. When the AlarmManager of my application runs on the background i could see a big delay on the device to respond to user events. Is it wise to have a widget that updates frequently?

Is it the recommended approach to update the widget..or can any one provide me some code samples or any application where the update happens frequently?.

Why is that the android:updatePeriodMillis is set to 30 mins?. Is it because Android does not want us to update a widget before that time interval?

Was it helpful?

Solution

I have a requirement where in i need to updated my widget once in every 15 seconds.

That is going to have repercussions for your battery life. Please make this configurable.

There is a method called android:updatePeriodMillis but that seems to be getting fired only after 30 minutes.

It is an XML attribute, not a method, and yes, it has a 30-minute minimum, because of complaints regarding battery life from users who install app widgets that update, say, every 15 seconds.

When the AlarmManager of my application runs on the background i could see a big delay on the device to respond to user events.

Put your time-consuming work in an IntentService, triggered by the alarm. If you are doing your work directly in a BroadcastReceiver onReceive() method, that runs at foreground priority and will have a greater impact on CPU usage. Also, it ties up the main application thread of your process, and so any activities you have running will be stuck while the BroadcastReceiver does its work.

Is it wise to have a widget that updates frequently?

IMHO, no, but if you make it configurable, then the user can choose what value they feel is appropriate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top