My Unity Android app is preventing the lock screen from displaying properly

I am working on a Unity project that is on iOS and Android. On Android, while the app is open, when the device sleeps and then the user hits the power button, the app is in the foreground. In this case, the user’s lock screen should come up. If the user hits the home button at this point, then the lock screen appears.

I have looked for all the various settings that I can think of that could be causing this behavior - running in the background, sleep timeout, etc. The project does not have any of these settings enabled. Other Unity apps that I have seen do not have this behavior.

Any ideas on what we could be setting or doing that would cause this behavior?

If you are in “Development Mode” this is the default behavior of the application.

Source: http://forum.unity3d.com/threads/game-is-preventing-the-lock-screen-from-appearing.205632/

I’m going to hazard a guess. I could be way off.

http://developer.android.com/reference/android/os/PowerManager.WakeLock.html

Wake-lock is set, asking the phone to stay on. Android is overriding this or the Screen Sleep is timing out and so the device sleeps anyway. When you resume, the lock-screen is still held in the queue as it was prevented by wake lock. When you press the Home button the wake lock is released and so the next queued intent is used which is the lock screen.

On Build, export your project as an Eclipse project. Once imported in to Eclipse check the XML manifest to see if Wakelock is allowed (if it is try disallowing it). Use eclipse to Run the app on your phone and check the LogCat info to see what is happening.

This may be one to post on StackOverflow.

Edit : Export to Eclipse is now “Google Android Project” in Build Settings, as of Unity 4.2