I have an app that needs to detect when the use locks his phone while it's activity is running. Right now the only way I have found is to make a loop with
KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if( myKM.inKeyguardRestrictedInputMode()) {
}
but it really doesn't seem like the right solution and uses up a LOT of cpu. Is there a better way?