Override onBackPressed in Android

Just curious if there’s an easier way to do things.

I extended the SDLActivity in MyActivity and wanted to override the back button in Android to use it to show a menu in Android side. Now, the usual way to do this is to override the onBackPressed method.

But it seems there’s a surface that grabs in it’s onKey method the back button down event before it gets a chance to go to the onBackPressed event…

So the way I found to do this was to detect the back button being pressed from my cpp code and there call the onBackPressed method from the extended activity. But if I do this, even though it works, the next time I call PumpEvents in the game, it crashes SDL.

Is there a proper way to do this on the extended activity so the back button handling never arrives for SDLActivity? Possibly avoiding code in the cpp part so I can just have this menu thing happen in the Android App. This is a menu that is used to debugging the game .