0

I'm developing Xamarin Forms app and I need to handle an event when physical button is pressed (on Android). What I've found out is that I can use DispatchKeyEvent inside an activity in Xamarin.Android project. However I don't know specifically how to do it.

In the shared code I have defined a ContentPage and I'm trying to override the DispatchKeyEvent inside a custom page renderer in Xamarin.Android. However, I get an error about missing constructor (I suppose it is related to layout, which is defined in the shared code, but I don't know why Xamarin.Android renderer doesn't use it).

How to solve this problem? Maybe there is some easier way to get info about key being pressed?

zionek
  • 1
  • Could you please share the full log of this error when you tried to override the DispatchKeyEvent inside a custom page renderer in Xamarin.Android ? – Jessie Zhang -MSFT Oct 24 '19 at 02:52

1 Answers1

0

In the code behind for your page, you can override OnBackButtonPressed.

protected override bool OnBackButtonPressed()
{
     return base.OnBackButtonPressed();
}
Daniel
  • 1,537
  • 1
  • 13
  • 16