I'm using the AlarmManger to schedule a keep alive timer to remote server, so every INTERVAL an UDP package are send to the server. Should I get a Wifi/CPU lock when the package sent or running on the AlarmManager context is enough? Note: I'm running a service to keep the application in background.
Asked
Active
Viewed 739 times
2
-
Welcome to Stackoverflow! If you find a response is helpful, please up vote it. If the response successfully answers your question, please click the green check mark next to it to accept the answer. Also please look at http://stackoverflow.com/questions/how-to-ask for advice on how to write a good question – Kurtis Nusbaum Nov 17 '11 at 19:46
1 Answers
0
Yes, you'll need a Wifi/CPU lock in order to be able to do this. A word of caution though, you're going to kill the users battery by doing this. You should figure out a way to communicate with your server asynchronously, like with REST. Android makes it really easy for people to figure out which apps are using up the most battery power, so unless you want a bunch of uninstalls, you should probably figure out a way around this.

Kurtis Nusbaum
- 30,445
- 13
- 78
- 102
-
Thanks for your answer. So what is the purpose of this flag: ELAPSED_REALTIME_WAKEUP? In the documentation... "which will wake up the device when it goes off [link](http://developer.android.com/reference/android/app/AlarmManager.html#ELAPSED_REALTIME_WAKEUP)." Maybe im getting it wrong? – mantemac Nov 17 '11 at 19:57
-
It will wake up the device if it's asleep. I never said your approach wasn't possible, just that it's likely to drain the battery if you do it a lot. Waking the device up and turning on the radio is totally doable, it's just not advised. – Kurtis Nusbaum Nov 17 '11 at 19:58
-
I'm writing sip client and i have to do so to keep NAT (router) open. Should i try some other approach? – mantemac Nov 17 '11 at 20:03
-
Ah, well in that case I'd say there's probably no way getting around this then. Go ahead and use your approach. This is one of those cases where you'll just have to keep the connection open. It's ok. I just wanted to make sure you weren't doing things that you didn't have to be doing. – Kurtis Nusbaum Nov 17 '11 at 20:04
-