- Home /
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?
Same problem here. Can't find a solution yet, will update if I do.
Has anyone solved this? Can't find anything about wake-lock in my manifest either.
Answer by Andy-Block · Apr 11, 2015 at 02:28 PM
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/
Answer by meat5000 · Aug 22, 2013 at 10:34 PM
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
Something like that... ;) It started with Android version 4.3. At least there i've noticed this behaviour first. It's not related to Unity since i can say almost for certain that before Android 4.3 the lock screen showed up after sleeping. We still use Unity 4.0.xx so it's not Unity related since we didn't update Unity, only the Android version.
Android 4.3 have brought some more problems. It seems $$anonymous$$ono has a bug which was not a problem until Android 4.3 came out.
Agreed. However I had games on A4.1.2 that skipped the lock screen on wake, so it is optional. I've got 4.2.2 now and that introduced some zany behaviours! After hitting home button sometimes my game would run as a wallpaper :D:D:D lol@$$anonymous$$ono bug link
Best not to live on the cutting edge. It effin hurts!
Actually, I can say for certain that it is not related to Android 4.3. I have devices ranging from 2.3 up to 4.3. It happens on all of them. I am on Unity 4.0.1 because newer versions of Unity crash on the Galaxy S2.
Bunny83, if you are certain that your project was once in a state where this wasn't happening, then I'm guessing you might be able to step back in your project to a state where this wasn't happening (assu$$anonymous$$g good version control). That would be very useful. In my case, this started happening from the first time I got the project running on Android, which was in January or February.
jhelton, are you exporting in to an environment that was setup and hasn't been changed for a while? For example, I've set up eclipse once and I've not touched it since except to import from Unity. Or do you build the Apk directly from Unity?
meat5000, I build the apk from Unity directly, kind of. We use a build script in unity to trigger the builds. This allows us to use Jenkins to do auto-builds. I haven't tried your Eclipse export suggestion, but my Android$$anonymous$$anifest.xml doesn't contain a wakelock permission.