Here's the situation : in my .Net Maui app, at various places I have to override the back button press with a custom command from my ViewMovel :
<Shell.BackButtonBehavior>
<BackButtonBehavior Command="{Binding BackButtonPressedCommand}" />
</Shell.BackButtonBehavior>
My problem is, whereas it works perfectly fine for the .Net Maui back button, it doesn't when it comes to the Android default back behavior (either by pressing the Back button at the bottom, or by sliding my finger from the right side to the left). I tested with some breakpoints and when I go back using these methods my custom command isn't called at all.
Any way to either override it as well, or to just disable it ? Or any workaround to handle this situation ?
Okay, thanks to @FreakyAli I actually found out the solution, and cleared up some misunderstading :
My misunderstanding was that calling the command from EventToCommandBehavior would actually override the native Android back as well. It actually only works from the internal Maui back button.
In order to act on the Android back action (either the physical back button at the bottom of the device in my screen, or the swipe from the right side of the screen of a device like a Google Pixel), one must override the OnBackButtonPressed method :
protected override bool OnBackButtonPressed()
{
return true;
// // Use the line above if you want to just disable the Back action.
// // If you want to instead bind it to the same command as
// // the BackButtonBehavior, use something like this :
//
// if (BindingContext is BaseViewModel vm)
// {
// vm.BackButtonPressed();
// return true;
// }
// return false;
}