0

I need advice. I'm trying to create an event by long pressing the back button. I found this code: https://stackoverflow.com/a/65031537/6473719 which is in kotlin and I have a little problem converting it to C # specifically I have a problem with this event:

private fun handleBackLongPress(): Boolean {
supportFragmentManager.primaryNavigationFragment?.childFragmentManager?.fragments?.forEach {
    if (it is OnBackLongPressedListener && it.onBackLongPressed()) {
        return true
    }
}
return false
}

would anyone know how to convert this to C #.

  • i think the answer you are looking for is here https://stackoverflow.com/questions/56913053/android-long-press-system-back-button-listener – Math_Guerin Mar 31 '22 at 23:13

1 Answers1

0

Xamarin Android long press back button

If you want to listen for the long back event in android, you can override method OnKeyLongPress in your activity:

      public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent e)
    {
        if (keyCode == Keycode.Back)
        {
            System.Diagnostics.Debug.WriteLine("------------->Back button long pressed ");
            return true;
        }
        return base.OnKeyLongPress(keyCode, e);
    }
Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19