0

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.

Rogue
  • 751
  • 1
  • 17
  • 36

1 Answers1

0

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Ok, thanks for answering. I'm gonna take a closer look to GCM. – Rogue May 02 '14 at 23:02
  • @Rogue: Well, chat is usually implemented with some sort of long-lived socket, like XMPP. And chat is usually only relevant while you are in the foreground. Users usually expect the foreground app to consume power. Its when apps consume power (or other resources, like bandwidth) when the app is *not* in the foreground that users get irritated. So you might choose different strategies for foreground (long-lived socket) and background (GCM with a long-period poll as backup) operation. – CommonsWare May 02 '14 at 23:05
  • Yes, XMPP was my first idea. But i can't use that protocol for technical reasons (the client chat on desktop uses a strange SQL system, so it won't be compatible) – Rogue May 02 '14 at 23:07