I want to post some data every 5 min to server, but when I lock the screen, the network is offline and I'm not sure my service is running.
The connection is not only WIFI but also GPRS and 3G.
anyone solve this question?
I want to post some data every 5 min to server, but when I lock the screen, the network is offline and I'm not sure my service is running.
The connection is not only WIFI but also GPRS and 3G.
anyone solve this question?
You should set an Alarm (using the AlarmManager), and use a WakeLock to wake the phone and perform your action when to ensure your action occurs (regardless of if the phone services are available or not).
Here is one thread about this (there are plenty of others): AlarmManager and WakeLock
Contrary to other peoples opinion, this is something perfectly reasonable to do (assuming you have considered the options).
You should use WifiLock. The the connection will not be lost even if the screen goes dark. If you want to use 3G,look here, particulary at answer by CommonsWare, you should use partial WakeLock then.
It is not good idea to do something like this. You should study your situation and determine when you really need to post some data.
Look at this one maybe help you.