I am trying to troubleshoot a problem on the Android version of an app. I think it has to do with system events. As a test I created the following bit of code:
[lua]
local txt = display.newText(“App Running”, display.contentCenterX,
display.contentCenterY, native.systemFont, 16)
local function onSystemEvent(event)
print ("Event: "…event.type)
end
Runtime:addEventListener(“system”, onSystemEvent)
[/lua]
When running this in the simulator, and simulating a suspend, I get the following output, which I expected:
[lua]
Windows simulator build date: Feb 13 2014 @ 02:24:13
Event: applicationStart
Event: applicationSuspend
Event: applicationResume
[/lua]
I compiled the code and placed in on my Android device (Galaxy S3), then fired up logcat. I did 3 tests – all with the same results:
- Let the screen time-out to black, then pressed the side button.
- Let the screen time-out to black, then pressed the home button.
- Press the side button to time-out screen, then pressed the home button.
For each test, I got the following output (disregarding the line numbers, of course):
[lua]
Line 3591: I/Corona ( 8861): Event: applicationStart
Line 5901: I/Corona ( 8861): Event: applicationSuspend
Line 6461: I/Corona ( 8861): Event: applicationResume
Line 6785: I/Corona ( 8861): Event: applicationSuspend
Line 6893: I/Corona ( 8861): Event: applicationExit
Line 12443: I/Corona ( 9423): Event: applicationStart
Line 12713: I/Corona ( 9423): Event: applicationSuspend
Line 14327: I/Corona ( 9423): Event: applicationResume
Line 14555: I/Corona ( 9423): Event: applicationSuspend
Line 14705: I/Corona ( 9423): Event: applicationExit
Line 18827: I/Corona ( 9615): Event: applicationStart
Line 19005: I/Corona ( 9615): Event: applicationSuspend
Line 20587: I/Corona ( 9615): Event: applicationResume
Line 20805: I/Corona ( 9615): Event: applicationSuspend
Line 20945: I/Corona ( 9615): Event: applicationExit
[/lua]
Why is this happening? I didn’t expect 3 cycles for each test… that’s not normal, is it? Why is suspend being executed right after a resume?
Am I not understanding how to use this?
Any help appreciated. Thanks!
–John