In the standard Corona docs, the sample code to detect the back key on Android seems to have a couple of flaws. Here’s the sample code:
if ( event.keyName == "back" ) then if ( system.getInfo("platform") == "Android" ) then return true end end return false
It doesn’t test for event.phase=“up”, and it tests for platform (which seems un-necessary) but it looks for “Android” instead of “android”. This code works:
if (event.keyName=="back") and (event.phase=="up") then if (system.getInfo("platform")=="android") then --do something return true end end return false
These are minor bugs, but it’s hard for me to believe that they have gone undetected. So can anyone tell me: is there a “better” version of the documentation that I have not found yet? Or does the original code work in some context?? Thanks.
If the goal is simply to catch and nullify the back key, then that’s reasonable. But if we’re processing the back key to perform some action?? Maybe not so good. And common Android apps perform their action when the back key is released --the “up” event-- so that’s standard on the platform, too.