Can I get rid of WakeLock?
<p>My app has a couple of services running in the background. They use: a long lived TCP connection, GPS, Accelerometer and android.os.CountDownTimer.</p>

<p>I already know the Accelerometer and CountDownTimer require a partial WakeLock to work when my phone goes to sleep (Android 2.2), GPS doesn't require a WakeLock, not sure about TCP sockets?</p>

<p>CountDownTimer hopefully can be replaced by java.util.Timer which I think will still work without a WakeLock? Then I can acquire/release the WakeLock for periodic Accelerometer checks. Then when the Acclerometer detects movement I can turn on the GPS. And if there is no GPS signal I can go back to my timer full circle.</p>

<p>Will this work without a permanent WakeLock? I don't know about the TCP connection.</p>

<p>EDIT:
Turns out you have to use an AlarmManager in deep sleep when no wakelock is set to get accurate timers.</p>

<p>The TCP socket works well enough without a wakelock:</p>

<p><a href="http://devtcg.blogspot.com/2009/01/push-services-implementing-persistent.html" rel="nofollow">http://devtcg.blogspot.com/2009/01/push-services-implementing-persistent.html</a></p>

<p>Some sample code, which tries to keep the socket alive:</p>

<p><a href="http://code.google.com/p/android-random/source/browse/#svn/trunk/TestKeepAlive" rel="nofollow">http://code.google.com/p/android-random/source/browse/#svn/trunk/TestKeepAlive</a></p>

<p>If you don't use setSoTimeout (or set to 0 for infinite) the socket seems to last a long time even without doing anything to keep it alive when the phone is sleeping. Although I am acquiring and releasing a WakeLock every minute in another service. I'm not sure what effect that has (if any) on the TCP socket.</p>
