Is using WakeLock overkill when using WifiLock on Android?

My audio streaming application only works correctly with WifiLock.

But some devices report that when they turn off the screen, the connection is interrupted and the audio streaming is exceeded. (They say this does not happen in 3G)

So, I thought that maybe I can also use Partial WakeLock. I'm not sure if this fixes the problem, but I think this is an option. At the same time, adding WakeLock while working with basic WifiLock can drain the battery faster and may not solve the problem.

What do you think of adding WakeLock for this type of problem and application?

private static WifiLock wifiLock = ((WifiManager) appInstance().getSystemService(Context.WIFI_SERVICE)) .createWifiLock((android.os.Build.VERSION.SDK_INT>=12?WifiManager.WIFI_MODE_FULL_HIGH_PERF:WifiManager.WIFI_MODE_FULL), "myappwifilock"); 

Recently added line:

 private static WakeLock wakeLock= ((PowerManager) appInstance().getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "myappwakelock"); 

(Of course, I acquire and release these locks to create a service and to destroy it.)

+3
android android-wifi android-wake-lock
source share
1 answer

Use both of them. The behavior that I'm sure varies from phone to phone. You might want to find devices that report on “wifi” or “wifi driver”. Are you sure that your audio streaming application only works correctly with WifiLock? This sounds very strange: the processor will sleep, and the service will stop - see Service, WakeLock . Something else is preventing the phone from waking up. So you need tracking lock

If you use only the wake lock, on the other hand, Wi-Fi will turn off, maybe I'm not sure that you are using it, but it's better safe than sorry. If he turns off the wake-up, the phone will not wake him - for this I am sure. Using wifi-lock does not affect the battery - there is a Wi-Fi radio, and you do it anyway.

So, both that and another - and be convinced that your service gets them - look at WakefulIntentService

+2
source share

All Articles