0

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();
    }
}
zhjh
  • 51
  • 1
  • 6

1 Answers1

0

It appears it changes between devices. I suspect possibly due to the manufacturer/ set software that is possibly killing threads.

I tested on about 5 different devices Huawei & Samsungs. The issue showed on Huawei devices mostly, newer version of Android. Possibly something that needs to be addressed.

Notes to take: WiFi may die if your phone screen dims and your not holding wakelock, depends on device. WiFi lock is a waste of time due to manufacturer differences.

zhjh
  • 51
  • 1
  • 6