Back Button Causes App Unusable

Hi,

I notice on my Samsung Note5 deice, that when the back button is pressed repeated (fast) when the app is loaded, it will go back to the main screen and further attempts to load the app will just show a blank screen. 

It seems that the app is ‘stuck’ in the ‘applicationSuspend’ state and is not able to get out of it when the app is launched again. To launch the app again, I will need to wait (~1 minute) until the Android-OS ask to close the app. The other option is to reinstall the app.

05-16 18:54:20.767 13676 14140 I Corona : system event : applicationSuspend 05-16 18:54:20.789 13676 14140 I Corona : Admob phase & type : displayed banner

After drilling down, disabling adMob or disabling  Runtime:addEventListener( “key”, onKeyEvent ) solves this problem. This is most likely because the system-events are captured properly (like below). 

.

05-17 00:26:59.525 18753 19061 I Corona : system event : applicationSuspend 05-17 00:26:59.985 18753 18753 I Corona : system event : applicationExit

.

Anyone experience this ? Using 2017.3075

If you are loading an ad on startup this could be the cause?  Also you should add code to your onKey event to only process a single back button press for good measure.

Thanks for the info. I am not loading an adMob during startup. It only happens after loading a page, then 2-seconds delay, and ad is shown (if .isLoaded, as per new adMob docs/requirements).

After spending more time to check (as this problem was not seen in the older builds using the older free-plugins, which are before 2017), i notice these that affects the suspend issue.

  1. Placing _Runtime:addEventListener( “key”, onKeyEvent ) _in ‘scene:show did’ and _Runtime:removeEventListener( “key”, onKeyEvent ) _in ‘scene:hide will’ will cause this problem. These items must be placed in ‘scene:create’ & ‘scene:destroy’ parts of the composer.
  2. When using back-button listener to goto another page (e.g. previous page), it must have a delay before going to another page again (e.g. when user presses back-button repeatedly).

Personally I would put the key handler in main.lua in this circumstance and make decisions based on what scene you’re in as to how you want to back out.

For instance, I will on first press jump to the menu scene and on the second press requestExit() since that’s sort of the Android expected behavior.

You can also set a flag to keep extra presses from happening until you’re ready to handle the next back press.

Rob

+1 Thanks

If you are loading an ad on startup this could be the cause?  Also you should add code to your onKey event to only process a single back button press for good measure.

Thanks for the info. I am not loading an adMob during startup. It only happens after loading a page, then 2-seconds delay, and ad is shown (if .isLoaded, as per new adMob docs/requirements).

After spending more time to check (as this problem was not seen in the older builds using the older free-plugins, which are before 2017), i notice these that affects the suspend issue.

  1. Placing _Runtime:addEventListener( “key”, onKeyEvent ) _in ‘scene:show did’ and _Runtime:removeEventListener( “key”, onKeyEvent ) _in ‘scene:hide will’ will cause this problem. These items must be placed in ‘scene:create’ & ‘scene:destroy’ parts of the composer.
  2. When using back-button listener to goto another page (e.g. previous page), it must have a delay before going to another page again (e.g. when user presses back-button repeatedly).

Personally I would put the key handler in main.lua in this circumstance and make decisions based on what scene you’re in as to how you want to back out.

For instance, I will on first press jump to the menu scene and on the second press requestExit() since that’s sort of the Android expected behavior.

You can also set a flag to keep extra presses from happening until you’re ready to handle the next back press.

Rob

+1 Thanks