How to open a native alert box when user presses on screen button or presses the back button

Really as the title says.

Those text boxes that pop up when you try to exit a game via the device back button or an ingame button before calling os.exit for example.

“are you sure ?” “yes” or “Cancel”

thank you

Hi @bubblebobble,

On the press of a button you create (on the screen), a standard native alert should work:

http://docs.coronalabs.com/guide/system/nativeUI/index.html

However, on the press of a hardware “back” button, I don’t think you’ll get this kind of functionality, because it will effectively terminate/exit the program before the alert shows up, and I don’t believe there’s any way to tell the OS “wait, the user pressed the back button, but don’t actually exit the app until they confirm on the screen!”.

But all of this said, is there a reason you’re using “os.exit”? This is generally not recommended, as Apple may view it as your app “crashing” and prevent it from being approved to market.

From a user standpoint… and this is just my opinion… when I press the “back” button or exit button, I know that I want to exit the app. A confirmation dialogue would be very odd to me, and probably somewhat bothersome too. :slight_smile:

Best regards,

Brent

Hi Brent,

I have used the native alert for the general “do you want to exit”, “yes” ,“no” now, no problems whatsoever. I also used the showpopup to link to the playstore and have to say how very simple this was, credit to CLs for this I expected some head scratching.

I asked about the device back button as I have seen lots of Apps using it, but I agree when the user presses the back button they usually want to exit whatever is on screen. I still wonder how its done though?

os.exit is not recommended then ? Ok so what is recommended ?

Thanks

ah…found it for android:

native.requestExit()

Yes, this is fine for Android. :slight_smile: You probably found the link on the “os.exit” documentation, which cites the reasons I gave above: http://docs.coronalabs.com/api/library/os/exit.html

Take care,

Brent

Hi @bubblebobble,

On the press of a button you create (on the screen), a standard native alert should work:

http://docs.coronalabs.com/guide/system/nativeUI/index.html

However, on the press of a hardware “back” button, I don’t think you’ll get this kind of functionality, because it will effectively terminate/exit the program before the alert shows up, and I don’t believe there’s any way to tell the OS “wait, the user pressed the back button, but don’t actually exit the app until they confirm on the screen!”.

But all of this said, is there a reason you’re using “os.exit”? This is generally not recommended, as Apple may view it as your app “crashing” and prevent it from being approved to market.

From a user standpoint… and this is just my opinion… when I press the “back” button or exit button, I know that I want to exit the app. A confirmation dialogue would be very odd to me, and probably somewhat bothersome too. :slight_smile:

Best regards,

Brent

Hi Brent,

I have used the native alert for the general “do you want to exit”, “yes” ,“no” now, no problems whatsoever. I also used the showpopup to link to the playstore and have to say how very simple this was, credit to CLs for this I expected some head scratching.

I asked about the device back button as I have seen lots of Apps using it, but I agree when the user presses the back button they usually want to exit whatever is on screen. I still wonder how its done though?

os.exit is not recommended then ? Ok so what is recommended ?

Thanks

ah…found it for android:

native.requestExit()

Yes, this is fine for Android. :slight_smile: You probably found the link on the “os.exit” documentation, which cites the reasons I gave above: http://docs.coronalabs.com/api/library/os/exit.html

Take care,

Brent