My background service sends messages to the local server as quickly as possible. Each message usually takes about 30 ms. But when the phone is in sleep mode, it takes about 400 ms-1000 ms (the screen is off with the βcorrectβ Wifi policy).
In my service, I use the following code to purchase Wifi-lock and WakeLock.
PowerManager lPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = lPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WakeLockTag"); WifiManager lWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { mWifiLock = lWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "LockTag"); } else { mWifiLock = lWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "LockTag"); } mWifiLock.acquire(); mWakeLock.acquire();
Is it possible to get the same performance as when the screen is on?
source share