Android Lockscreen not shown when screen times out. (Wakelock?)

I am building an android app using Unity and it is coming along very well. However, I’m having an odd issue relating to the screen timing out and the lockscreen not showing.

What Should Happen

  • User stops playing
  • Screen Times out and turns off
  • Later, player returns and turns their phone back on
  • Lockscreen shows, user can enter their password, or otherwise unlock their phone
  • App regains focus and continues

What IS happening

  • User stops playing
  • Screen Times out and turns off
  • Later, player returns and turns their phone back on
  • Lockscreen does NOT show! The app is right in focus, bypassing the lockscreen all together
  • Users get mad that their security is compromised :frowning:

Notes

  • This happens regardless of whether or not I’m using Android Plugins
  • I’m using Unity 4.2.0f4 (Though the changelogs for the more recent versions have nothing about this issue)
  • It even happens on a blank Android project
  • I’ve tested this on 5 different devices, all have the same problem

I suspect that this is caused by a wakelock that Unity does not give up when the screen times out. This causes the app to hold focus and the lockscreen never gets to ‘load’. This is a pretty serious problem.

Does anyone know of any way to fix this?

I also faced this problem today. After short investigation found out that lockscreen isn’t working as it’s expected only in developnemt builds. When “Development Build” in “Build Settings” was off, everything worked just fine. Btw. I’m using Unity 4.5.2.

I also asked this question on StackOverflow to see if I could get an answer there. After a few answers I was able to put together a workaround. This is my work around. It’s not ideal, but I’ve submitted a bug report so hopefully this gets fixed soon.

This is still a problem in version 2019.3.0f6.

Like @Meic mentioned, unchecking “development build” fixes it.