My WakeLock isn't keeping my device awake.
In OnCreate()
I've got:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "My Tag"); mWakeLock.acquire();
then:
new CountDownTimer(1320000, 200) { public void onTick(long millisUntilFinished) { // I update a progress bar here. } public void onFinish() { // I finish updating the progress bar. mWakeLock.release(); } }.start();
The screen turns off before the timer finishes, how can I make the screen stay visible?
mWakeLock
is a field previously declared like so:
private PowerManager.WakeLock mWakeLock;
My device uses Android 1.6. I would really appreciate any help to resolve this.
To release the wake lock, call wakelock. release() . This releases your claim to the CPU. It's important to release a wake lock as soon as your app is finished using it to avoid draining the battery.
A wake lock is a mechanism to indicate that your application needs to have the device stay on. Any application using a WakeLock must request the android. permission. WAKE_LOCK permission in an <uses-permission> element of the application's manifest.
A wakelock, in layman's terms, is just a way for an app to keep the CPU/screen/other things awake when the phone is idle in order to perform a specific background task.
Click on the wakelock you want to block, press the "Block" button and then set for how long is the wakelock gonna be blocked!
WakeLock doesn't usually cause Reboot problems. There may be some other issues in your coding. WakeLock hogs battery heavily, if not released after usage.
WakeLock is an Inefficient way of keeping the screen on. Instead use the WindowManager to do the magic. The following one line will suffice the WakeLock. The WakeLock Permission is also needed for this to work. Also this code is more efficient than the wakeLock.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
You need not relase the WakeLock Manually. This code will allow the Android System to handle the Lock Automatically. When your application is in the Foreground then WakeLock is held and else android System releases the Lock automatically.
Try this and post your comment...
Do you have the required permission set in your Manifest?
<uses-permission android:name="android.permission.WAKE_LOCK" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With