Android Prevent Back Button Exit

At some point back button behavior changed and stopImmediatePropagation is not working anymore - android app just quits. OpenFL 4.8.1 and Lime 3.7.4
The code I use:

private function onKeyUp(e:KeyboardEvent):Void
{
	switch(cast e.keyCode)
	{
		case KeyCode.APP_CONTROL_BACK:
			e.stopImmediatePropagation();
			e.stopPropagation();
			_currentScreen.onBackButton();
		case KeyCode.ESCAPE:
			e.stopImmediatePropagation();
			e.stopPropagation();
			_currentScreen.onBackButton();
	}
}

There is this code in NativeApplication.hx:358 that I think is causing this:

if (keyCode == APP_CONTROL_BACK && modifier == KeyModifier.NONE && type == KEY_UP && !window.onKeyUp.canceled) {
				
	System.exit (0);
				
}

So, what is the current way to prevent app from quitting when BACK is pressed?

I think they changed it to e.preventDefault().

2 Likes

Works like a charm. Thanks!