Reputation: 636
When I start service which send some data to server every few seconds I acquire
wakeLock
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
wakeLock.acquire();
and wifiLock
WifiManager wMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiLock = wMgr.createWifiLock(WifiManager.WIFI_MODE_FULL, "MyWifiLock");
wifiLock.acquire();
But if device is not touched for one hour and is in sleep mode wifi stop working. Is this normal behaviour and if not, what should I do to lock device until release()
method are called?
Upvotes: 0
Views: 1384
Reputation: 7761
Android dozes off the device when it is left unused for some time to optimise battery performance, so yes it is a normal behaviour.
Firstly, it is highly recommended for that you don't try to stop the device going to doze off mode, for the betterment of battery performance of the device. You can read more about dozing off here in the official documentation.
If you have a strict requirement for some reason that you need to keep your service active, you can probably try adding REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission in your app. But be advised that your app may get rejected from the Google Play Store (if it is supposed to be published there) on the basis of the quotation below from the official documentation here:
Note: Google Play policies prohibit apps from requesting a direct exemption from Power Management features in Android 6.0+ (Doze and App Standby) unless the core function of the app is adversely affected.
Upvotes: 4