简体   繁体   English

具有PROXIMITY_SCREEN_OFF_WAKE_LOCK级别的Android WakeLock会导致调用onPause

[英]Android WakeLock with PROXIMITY_SCREEN_OFF_WAKE_LOCK level cause onPause to be called

In my android application I use PROXIMITY_SCREEN_OFF_WAKE_LOCK WakeLock so that the screen is turned off when proximity sensor is activated. 在我的Android应用程序中,我使用PROXIMITY_SCREEN_OFF_WAKE_LOCK WakeLock,以便在激活接近传感器时关闭屏幕。

The Android documentation says: Android文档说:

However, the device will not fall asleep while the screen has been turned off by the proximity sensor because it effectively counts as ongoing user activity. 但是,由于接近传感器已关闭屏幕,因此该设备不会进入睡眠状态,因为它实际上算作正在进行的用户活动。

But when the sensor is activated and the screen is off; 但是当传感器被激活并且屏幕关闭时; the onPause event of my activity is called, and onResume is called again when the screen is on. 我的活动的onPause事件被调用,并且在屏幕打开时再次调用onResume Does it mean that the device go to sleep when the screen is off? 这是否意味着屏幕关闭时设备进入睡眠状态? any suggestion on how to prevent my activity from pausing when the screen is off? 关于如何防止屏幕关闭时我的活动暂停的任何建议?

use PARTIAL_WAKE_LOCK, instead of PROXIMITY_SCREEN_OFF_WAKE_LOCK it will work for you. 使用PARTIAL_WAKE_LOCK,而不是PROXIMITY_SCREEN_OFF_WAKE_LOCK ,它将为您服务。 and acquire it in your activity oncreate() and release in onPause() . 并在您的活动oncreate()中获取它,并在onPause()中释放它。

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

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