0

I am working with Xmarine c# anroid app. Here I am unable to close the app on back button pressed. In my app on the landing activity (Activity1) we will get 3 buttons, each button will open a new activity (inner1,inner2,inner3). Now if we click back button from any of these 3 inner activity then it will come to the landing activity (Activity1).It is working fine. Now if we click back button from (Activity1) the app does not close and every time it repoens the landing activity.

Where as I need to close the app at the time of back button press of (Activity1). How to close app on back button press.

Here I have used the below mentioned code for performing closing activity from Activity1 back pressed.

Process.KillProcess(Process.MyPid());

Also I have used the below mentioned code for redirecting the Landing activity from all inner1, inner2, inner3 activity back press.

public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
        {
            if (e.KeyCode == Keycode.Back)
            {                
                // Transition your Fragments here
                var Activity = new Intent(this, typeof(Activity1));
                StartActivity(Activity);
                Finish();
            }

            return base.OnKeyDown(keyCode, e);
        }
Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51
Soumen Halder
  • 117
  • 1
  • 13

2 Answers2

3

You can use the below codes to exit from the app

this.Finish();
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
System.Environment.
Midhun Murali
  • 921
  • 6
  • 11
0

if you are using intent from first activity you dont want to define back pressed method , if you click the back button its automatically redirect to landing activity

Archu Mohan
  • 199
  • 1
  • 5
  • 14