Reputation: 165
my app maintains a socket connection with a server through a Service I coded, but once the phone sleeps (a couple minutes after the screen turns off), I am unable to get the typical response from the sleeping phone. A sound is normally played when the Service receives a network event.
My question is, do I need a wake_lock to be able to have my app function. If so, for what components is this wake_lock helpful for? I am curious about the sound and the socket connection. Will I be able to do this with only a partial wake_lock?
As for the socket connection, will I need an additional wifi lock if it is done under wifi? The socket connection only consists of small transaction once a while, so is there a way that I can have the socket connection not under wifi (even if the user enabled wifi), so I don't have to wifi lock and waste power? or are socket connection conveniently done only under 3g/4g or can gracefully degenerate from wifi to 3g/4g?
Thanks!
Upvotes: 0
Views: 1671
Reputation: 1007321
do I need a wake_lock to be able to have my app function
Generally, yes. If your network connection is via mobile data and if you have an open socket to a server and if that server sends packets to you, that will wake up the phone briefly. However, to do any serious work, you need to then acquire a WakeLock
. And if any of the italicized if statements from above are not true, then you need a WakeLock
as long as you are trying to maintain this connection.
Hence, please consider switching to C2DM for push notifications.
Will I be able to do this with only a partial wake_lock?
A partial WakeLock
should suffice.
will I need an additional wifi lock if it is done under wifi?
Yes.
is there a way that I can have the socket connection not under wifi (even if the user enabled wifi), so I don't have to wifi lock and waste power?
Not really. You request the socket connection. You use whatever network is active at the time.
or are socket connection conveniently done only under 3g/4g or can gracefully degenerate from wifi to 3g/4g?
Network connectivity gracefully falls back to mobile data if WiFi powers down or otherwise becomes unavailable. However, socket connnections do not. If you have a socket connection on WiFi, and WiFi powers down, your socket is closed, and you would need to reopen it on the new network.
Upvotes: 1