- Home /
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 :(
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?
Answer by Khalos · Nov 12, 2013 at 02:48 PM
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.
Is this in the Issue Tracker? Any response from your bug report?
It is in the issue tracker, it's still open and as far as I can see no one has responded. Here's the ticket.
Answer by Meic · Sep 18, 2014 at 02:51 PM
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.
Good thought.
I tested this myself and can confirm that on Unity 5.5.1 that the behavior is for a development build to come back immediately when locking and unlocking via the power button, but a non-development build requires the user to unlock by going through regular security: entering PIN, password, fingerprint, etc. So the app is certainly working as expected on a non-development build. The only thing is whether it's even worth having this special behavior on a development build at all, since it's causing confusion. If a dev wants a device to stay on all the time, there's an Android developer setting to do so when the device is plugged into a USB, such as when plugged into a PC to issue ADB commands.
Answer by computerCondom · Jul 22, 2020 at 02:01 AM
This is still a problem in version 2019.3.0f6.
Like @Meic mentioned, unchecking "development build" fixes it.
Your answer
Follow this Question
Related Questions
Android Auto scale backgorund for any resolution 2 Answers
Is there is a way to play movie within unityplayer on android? 1 Answer
How should I begin developing for Android in Unity? 1 Answer
Sensitivity on Android Input.acceleration 2 Answers
Finish UnityPlayerActivity in android unity project 0 Answers