Screen turns off immediately when setting systemIdleMode to NORMAL after having been in KEEP_AWAKE
I've found a little issue in Android...
In my application I download some files the first time it's run. Since it takes a couple of minutes without user input, the screen turns off automatically. I've found some tablets not only turn off the screen but also interrupt the download altogether when going to sleep, so to avoid this I'm using this to prevent the screen from turning off (is there any other workaround to prevent downloads being interrupted by sleep?):
| NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE; |
Of course, I've also added the WAKE_LOCK and DISABLE_KEYWARD permissions to my app descriptor, so the above code works. The problem is that I don't want the app to stay awake all the time, so after the download finishes, I'm setting the screen back to normal with:
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
But after executing that, the screen goes off immediately, instead of waiting for a minute or so before dimming the screen. It's as if the dimming was triggered already during the download process, but didn't actually happen because of the KEEP_AWAKE setting, and then when switching to NORMAL, the screen dimming takes place immediately so it turns off.
Is this an intended behaviour or should I file a bug?
How can I manage to set the systemIdleMode to NORMAL but still have the screen on waiting a bit before going to sleep? Turning off the screen as soon as the download is finished is confusing for the user, who might think the app has frozen when it's really just in sleep mode (and the user has to unlock the screen before going back to the app).
This happens in just about any version of AIR 3.x (and probably below).
Also, it happens in iOS as well, but it's less dramatic because the screen just dims a little (app is still visible) when setting systemIdleMode to NORMAL, instead of turning off completely and locking the screen, which is the behaviour in Android.