Is there a way to make native.requestExit() ask if the user if they want to leave the app?

At the moment, my Android app will kill itself if the user presses the back button when on the main menu. My issue is that it does it immediately, so if they press it by mistake the app is shut down.
Is there a native “Are you sure?” function built in to native.requestExit?

I could use a native alert and then call requestExit if they press yes, the problem there is that I would need to translate this for all languages that we use which is more time and expense. If there was a built-in confirmation box that used the devices language preference, that would be ideal.

Does anyone know if this exists? I haven’t found anything that suggests it does, but thought I’d ask anyway. [import]uid: 84115 topic_id: 33941 reply_id: 333941[/import]

Also, am I right in thinking it is not mandatory to have the ability for the back button to kill an app? I’m pretty sure I have some apps that can only be killed by doing it manually. [import]uid: 84115 topic_id: 33941 reply_id: 134947[/import]

You’d need to add some code to handle the android back key… The docs are at:

http://www.coronalabs.com/blog/2011/07/15/make-use-of-android-hardware-buttons/
http://docs.coronalabs.com/api/event/key/index.html

And the code would look something like:

local function onAndroidKeyEvent(event) -- Handler for android Back and other keys...   
local retVal = false  
  
 if( event ~= nil ) then   
 local phase = event.phase  
 local keyName = event.keyName  
 print("onAndroidKeyEvent() --- ("..phase.." , " .. keyName ..")")  
   
 if( (keyName == "back") and (phase == "down") ) then   
 retVal = true  
 backListener(event)   
 end  
 end  
  
 return retVal  
end  
  
-- The call to set the android buttons/key event listener...  
Runtime:addEventListener( "key", onAndroidKeyEvent ) -- Handler for android Back and other keys...   

The app will only exit if this listener returns false (true means you handled it, false directs the OS to handle it, and droid will exit).

One method would be to handle the back key, show a dialog asking if they want to exit, and if so, then call requestExit. [import]uid: 79933 topic_id: 33941 reply_id: 134964[/import]

Thanks for that, but I already know how to handle the back button itself.
What I was actually looking for was whether or not there is a “Are you sure you want to exit the app popup?” built in to the requestExit function. Ideally I do not want the back button to close the app instantly.
As I said in my first post I could use an alert view to get around this, but this would need translating for other languages. If the OS already had the feature built in, then presumably it would use the users default language.

My second post was more of a general question on whether all Android apps must have the ability to kill the app from within the app, seeing as there are plenty of music ones that carry on playing music when you press back, I guess not. [import]uid: 84115 topic_id: 33941 reply_id: 134966[/import]

Also, am I right in thinking it is not mandatory to have the ability for the back button to kill an app? I’m pretty sure I have some apps that can only be killed by doing it manually. [import]uid: 84115 topic_id: 33941 reply_id: 134947[/import]

You’d need to add some code to handle the android back key… The docs are at:

http://www.coronalabs.com/blog/2011/07/15/make-use-of-android-hardware-buttons/
http://docs.coronalabs.com/api/event/key/index.html

And the code would look something like:

local function onAndroidKeyEvent(event) -- Handler for android Back and other keys...   
local retVal = false  
  
 if( event ~= nil ) then   
 local phase = event.phase  
 local keyName = event.keyName  
 print("onAndroidKeyEvent() --- ("..phase.." , " .. keyName ..")")  
   
 if( (keyName == "back") and (phase == "down") ) then   
 retVal = true  
 backListener(event)   
 end  
 end  
  
 return retVal  
end  
  
-- The call to set the android buttons/key event listener...  
Runtime:addEventListener( "key", onAndroidKeyEvent ) -- Handler for android Back and other keys...   

The app will only exit if this listener returns false (true means you handled it, false directs the OS to handle it, and droid will exit).

One method would be to handle the back key, show a dialog asking if they want to exit, and if so, then call requestExit. [import]uid: 79933 topic_id: 33941 reply_id: 134964[/import]

Thanks for that, but I already know how to handle the back button itself.
What I was actually looking for was whether or not there is a “Are you sure you want to exit the app popup?” built in to the requestExit function. Ideally I do not want the back button to close the app instantly.
As I said in my first post I could use an alert view to get around this, but this would need translating for other languages. If the OS already had the feature built in, then presumably it would use the users default language.

My second post was more of a general question on whether all Android apps must have the ability to kill the app from within the app, seeing as there are plenty of music ones that carry on playing music when you press back, I guess not. [import]uid: 84115 topic_id: 33941 reply_id: 134966[/import]