Question

I'm using a BroadcastReceiver combined to a AlarmManager in my app to fetch periodically my user's notifications. To do so, i have to make calls to the Rest API of my service. My question is more about good practice than technique, i'm concerned about battery and network usage (over cellular networks). So, if the user sets the refresh period to 5s, will this be a huge problem for his battery, following this pattern (a Rest call every 5s via a BrodcastReceiver), or is there a better way to do this ? Note : i'm already using setInexactRepeating instated of setRepeating on my AlarmManager.

Thanks for reading.

Was it helpful?

Solution

So, if the user sets the refresh period to 5s, will this be a huge problem for his battery

Yes. On the other hand, if the user requested that, so long as the user is aware of the power drain, that is the user's choice. I would default to something much less frequent, like once an hour.

Note : i'm already using setInexactRepeating instated of setRepeating on my AlarmManager.

setInexactRepeating() only has the "inexact" effect if you choose one of the stock values (e.g., INTERVAL_FIFTEEN_MINUTES) or are running on API Level 19+. If you want to leverage that "inexact" nature for power savings, you should only allow the user to choose one of the INTERVAL_* values.

Also, depending upon what "user notifications" are, consider using GCM to push them down, rather than using frequent polling.

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