Josh Russo Josh Russo - 1 month ago 9
Android Question

The appropriate way to leave an Android app? (Xamarin)

I'm developing an Android using Xamarin. The app has a login modal and I would like the behavior of the back button on the login modal to essentially exit the app, as if you were at the end of the navigation stack.

Is this possible?

Answer

If you are displaying the modal on android via a new Activity, override OnBackPressed in the modal activity like so:

public override void OnBackPressed()
{
            Intent intent = new Intent(Intent.ActionMain);
            intent.AddCategory(Intent.CategoryHome);
            intent.SetFlags(ActivityFlags.NewTask);
            StartActivity(intent);
}
Comments