I have an app holding the PARTIAL_WAKE_LOCK on startup and then releasing onDestroy. Randomly it crashes after some time 40min - 2 hours when the device is just left alone/screen is dimmed.
After some investigations I found that releasing the wake lock onPause stops this issue from happening. However this is not desired, I would like the lock to stay on even when the screen is turned off.
Can anyone tell me if it essential to release the wake lock onPause? Or any other suggestions would help.
Basic implementation:
public class myActivity extends Activity {
PowerManager.WakeLock wakeLock;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WakeLock");
wakeLock.acquire();
}
@Override
public void onDestroy() {
if (wakeLock.isHeld()) {
wakeLock.release();
}
super.onDestroy();
}
}