Search code examples
androidandroid-activityandroid-intentlockscreenwakelock

Android lock screen show again after it has been disabled (using lock.disableKeyguard())


Hey Im writing a launcher, in which Im building my own custom lockscreen.

the custom lockscreen is an activity which being launched whenever the screen is off (by listening to Intent.ACTION_SCREEN_OFF)

to disable android's lockscreen I use this code:

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();

It all works good, till some point, in which android's lockscreen is turned on again (like it has never beem disabled before).

It happens a lot on samsung galaxy 2 (but happens also on other phones).

What Im I doing wrong?

thanks!


Solution

  • Managed to solve it somehow by calling

     KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
     KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
     lock.disableKeyguard();
    

    right before I start the lock screen activity