Disabling back button C# Android Xamarin Code Not Responding

Viewed 13319

So im trying to disable the back button in my app and it seems like the code im using doesnt want to respond, its hard to explain in words so I made a gif so you can see it more clearly and understand because im not sure I will be able to explain in words.

I want to disable the back button in "Activity2" but the codes I've been trying doesnt want to respond to the back button Here is the GIF

Ive tried these codes, dont know any more solutions since im new to android development.

First attempt

public override void OnBackPressed ()
    {
    base.OnBackPressed ();
    }

Second attempt (Both did the same thing)

public override void OnBackPressed ()
    {
       //  base.OnBackPressed ();            /*  Comment this base call to avoid calling Finish()  */
       //  Do nothing
    }

What could the possible issue be here?

5 Answers

Do Just Like This

public override void OnBackPressed()
{
    return;
}

You can Try like this
Step 1 Add [Activity(NoHistory =true)
Step 2 Add
protected override bool OnBackButtonPressed() { return true; }
to your content page that you want to disable Back Button Pressed.

Related