Ask user if he/she really wants to go back when back button press on android


#1

I want to ask user if he/she really wants to go back when back button press on android,
I have this event listener:

if (application.android) {
                application.android.on(application.AndroidApplication.activityBackPressedEvent, backEvent);
            }

and in the backEventFunction I have a dialog, I want user go back only when chooses leave,
but its not waiting for users choise its going back before choose yes or no.


#2

if (application.android) {
application.android.on(AndroidApplication.activityBackPressedEvent, (data: AndroidActivityBackPressedEventData) => {
// open the dialogue here
// and you need to use data.cancel = true; if you don’t want to go back
});
}