简体   繁体   English

在onResume()中,如何识别是否由于屏幕锁定或应用程序最小化而调用了onPause()

[英]At onResume() how to identify if onPause() was called because of screen lock or app minimised

I have a binder service which binds at onResume. 我有一个绑定服务,它在onResume上绑定。 At onResume I want to check if the previous onPause was called because of app minimised or screen was lock by lock button. 在onResume上,我想检查是否由于应用程序最小化而调用了先前的onPause或屏幕被锁定按钮锁定了。 I have tried with ACTION_SCREEN_ON and ACTION_SCREEN_OFF and setting a boolean value, but the problem is my binder at onResume get called before receiver gets the value. 我尝试使用ACTION_SCREEN_ON和ACTION_SCREEN_OFF并设置一个布尔值,但是问题是我的onResume的绑定器在接收器获取值之前被调用。

use below code to detect whether screen is locked in onPause() method 使用下面的code来检测screen是否在onPause()方法中被锁定

KeyguardManager km= (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if( km.inKeyguardRestrictedInputMode()) {
 //Screen is locked
} else {
 //it is not 
}

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

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