0

I have a binder service which binds at onResume. At onResume I want to check if the previous onPause was called because of app minimised or screen was lock by lock button. 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.

pheww
  • 163
  • 2
  • 2
  • 8

1 Answers1

0

use below code to detect whether screen is locked in onPause() method

KeyguardManager km= (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if( km.inKeyguardRestrictedInputMode()) {
 //Screen is locked
} else {
 //it is not 
}
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37