本文介绍了如何获得一个Android WakeLock工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我WakeLock不会再让我的设备醒了。

My WakeLock isn't keeping my device awake.

的OnCreate()我有:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "My Tag");
mWakeLock.acquire();

然后:

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 是一个场previously像这样宣布:

mWakeLock is a field previously declared like so:

private PowerManager.WakeLock mWakeLock;

我的设备采用Android 1.6。我真的AP preciate任何帮助解决这个问题。

My device uses Android 1.6. I would really appreciate any help to resolve this.

推荐答案

WakeLock通常不会导致重新启动的问题。有可能是你的代码的一些其他问题。WakeLock猪电池严重,如果使用后,不会发布

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是保持在屏幕的低效的方式。而是使用窗口管理器做的神奇。下面的一行就足够了WakeLock。 另外这款code是效率比wakeLock。

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. Also this code is efficient than the wakeLock.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

您不必RELASE的WakeLock手动。这code将使Android系统来处理自动上锁。当应用程序在前台运行,然后WakeLock保持和其他Android系统会自动解锁。

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...

这篇关于如何获得一个Android WakeLock工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 23:18