How to close app by back button double click

I want close app by android back button

First, click back button, open dialog

In this state, I want both dialog button and back button to close the app
However, dialog button works but back button doesn’t work

Flow of the code

initialize variable flag to false

click back button 1st time
skip if ~~
execute else (show dialog and set flag to true)

click back button 2nd time ← not work
execute if (close app)

Is there any way to close dialog by touching outside of dialog?

It should be simple logic problem…
But it doesn’t

for debugging, I tried to set dialog’s button text to variable
remove initialization at choose event

press back button
result is False
press back button again, nothing change

press back button
result is False
close dialog
press back button again
app close

So a conclusion is that back button pressed event do not work while dialog open

This is My solution


Use alert instead of dialog
Use Clock1.SystemTime
Double click less than 1 second close the app

Clock1.Now occur an error
image

No

Convert the system time into millis or use clock methods to calcukate the time difference

Taifun