I have an application which works on a user’s session which is maintained between the server and the device. I using a ping technique to keep the session alive between the device and server by pinging the server every 1 min if the user is logged in. This is done using a background thread.
-
Sometimes when I turn OFF the screen and disconnect the device from its power source the background thread gets killed.
-
Sometimes the thread is active but my WiFi antennae gets turned OFF and my ping fails.
Is my approach correct? Is there a better way of doing this?
My requirement: I need to ping my server every minute to keep the session alive for various reasons and I should do this only if the user is logged in.
You can use this to check your wi-fi connection
if checkInternetConnection() == false you can turn on wi-fi using this in your manifest
and this in your code
I hope this help you, though this is not an exact answer to your question.