Sometimes corona doesn't send a suspend system event on Android

This only happens if the game is suspended with the power button or is put into sleep mode. It doesn’t happen if the game is suspended by the home button.
I’m printing all system events to console. If suspended as described above, sometimes no suspend event is dispatched. This means we cannot save the game and we cannot mute/kill music playback. When the game is resumed, the (missing) suspend event and then the resume event gets dispatched.
We received memory warnings sometimes (and resolved them), maybe this helps you finding the problem.
This issue exists on multiple projects, not just one game.

reproduced on several Samsung Nexus One devices
Android Version 4.0.x, seems not to happen on 2.2!
tried corona version 807, 818 and 819
[import]uid: 107641 topic_id: 26663 reply_id: 326663[/import]

Hello Thomas,

I just tested daily build 819 with sample app “Hardware/SystemEvents” on my Samsung Galaxy Nexus, which is an Android 4.0.3 device. The suspend/resume system event happened every time for me when I pressed the power button. I tested it with the Home button too. I also tried letting the phone go to sleep mode on its own too and it still suspended correctly. I did not see any memory warning either.

So, I’m not able to reproduce this issue. Can you try running the above mentioned sample app on your Android 4.x phone to reproduce this issue? Because I need a reproducible case before I can investigate this further. Thanks! [import]uid: 32256 topic_id: 26663 reply_id: 108107[/import]

I cannot reproduce it on our device (Nexus S, android 4.0.4) with the SystemEvents sample app either.
But i was able to reproduce it every time if i add the following lines to the SystemEvents app:

[lua]local function update()
–wait a ms
local updateStart = system.getTimer()
while system.getTimer() - updateStart < 1 do end
end
Runtime:addEventListener( “enterFrame”, update )[/lua]

The Last callback event etc. displayed on screen never changes. There is always applicationStart as last callback event shown and previous event is nil. There is an “application does not respond” sytem popup too, if i suspend and restart it with the power off button.
Doing stuff one millisecond shouln’t be a problem? The update is called every 30ms anyway. Maybe the corona suspend callback takes to long and gets killed by the OS?
I hope this will help you finding the cause of the problem.
[import]uid: 107641 topic_id: 26663 reply_id: 108487[/import]

Thomas,

The [lua]system.getTimer()[/lua] function will not increment while the app is suspended. So what’s happening here is that the “enterFrame” event is occurring just before the “resume” event on Android 4.x, and because of this, that timer function is returning the same time value over and over again and you are stuck in an infinite loop. You can prove this by print the returned time value within that [lua]while[/lua] loop. You can work-around this by calling the [lua]os.clock()[/lua] function instead which always increments even while the app is suspended.

We’ll look into why the events are getting out of order on Android 4.x later. I know the Android OS likes to resume an app at the screen-lock window, which is bad behavior for games and we went well out of our way to block… but there is likely an additional step we need to take to make this work on Android 4.x. Thanks for bringing this to our attention. [import]uid: 32256 topic_id: 26663 reply_id: 108525[/import]

Thomas,

The issue where “enterFrame” events were occurring before the “applicationResume” event (while the app is suspended) has been fixed in daily build #847. That build will be available tomorrow. Thank you for bringing this issue to our attention. [import]uid: 32256 topic_id: 26663 reply_id: 114871[/import]

Thank you Joshua.
We will try to reproduce the bug with the new build. [import]uid: 107641 topic_id: 26663 reply_id: 115308[/import]