简体   繁体   English

PowerManager和PARTIAL_WAKE_LOCK

[英]PowerManager and PARTIAL_WAKE_LOCK

My app works fine when the device is plugged in the power supply whereas it fails (time to time) when the device is unplugged. 当设备插入电源时,我的应用程序运行良好,而当设备拔出电源时,我的应用程序却无法正常工作。 I think that the piece of code responsible of this issue is as follows: 我认为负责此问题的代码段如下:

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "foo");
    wl.acquire();
foo();
    wl.release();

foo() is a function that invokes a Camera.takePicture() that, as you know, results in a parallel task that takes a couple of seconds to complete. foo()是一个调用Camera.takePicture()的函数,如您所知,该函数会导致并行任务完成,该任务需要几秒钟才能完成。 Thus, wl.release() is actually called when the picture has not yet taken. 因此,当尚未拍摄照片时,实际上会调用wl.release() The above code is executed by an alarm which wakeup the device from its standby mode. 上面的代码由警报执行,该警报将设备从待机模式中唤醒。 My question is, is there the risk that the device returns in its standby mode before the picture has been taken due to the fact that wl.release might be called before the picture is taken? 我的问题是,由于在拍照之前可能会调用wl.release的事实, wl.release是否有在拍照之前返回待机模式的风险? Does wl.release() release instantaneously the PARTIAL_WAKE_LOCK or the device remains in its run mode for a while? wl.release()是否wl.release()释放PARTIAL_WAKE_LOCK或设备保持其运行模式一段时间?

Many thanks in advance for any comment. 非常感谢您的任何评论。

My question is, is there the risk that the device returns in its standby mode before the picture has been taken due to the fact that wl.release might be called before the picture is taken? 我的问题是,由于在拍照之前可能会调用wl.release的事实,设备是否有在拍照之前返回待机模式的风险?

Yes. 是。

Does wl.release() release instantaneously the PARTIAL_WAKE_LOCK wl.release()是否立即释放PARTIAL_WAKE_LOCK

Yes. 是。

or the device remains in its run mode for a while? 还是设备保持其运行模式一段时间?

That depends on what else might be holding a WakeLock . 这取决于还有哪些可能持有WakeLock

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM