I am developing an app that needs to use both wifiLock and wakeLock so the audio streaming when the screen is off does not get disturbed. I have tried my app on Android 2.3 and wakeLock and looks like wifiLock work as expected so there is no difference between when the screen is on or off, but the same app on Android 4.2 (Jelly-bean) when the screen goes off is not working as well and the audio gets choppy which shows either wakeLock or wifiLock are not working correctly. Is there any reason for this?
Here is how I acquire and release the locks, in my main activity I have:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyWirelessHeadphone");
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL , "MyWifiLock");
...
}
@Override
protected void onDestroy() {
super.onDestroy();
if (wakeLock.isHeld()==true)
wakeLock.release();
if (wifiLock.isHeld()==true)
wifiLock.release();
}