0

I am trying to finish my previous activity but I don't know how to do that. I search about and how to do finishActivity() but I'm getting error. I also tried this method:

private void Finishactivity(Activity activity)
        {

                    activity.Finish();
        }

and call the method like Finishactivity(the-activity-I-want-to-close); but still getting error. How can I figure this out? I'm a beginner in C#.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • https://developer.xamarin.com/api/member/Android.App.Activity.Finish/ – AskNilesh Jun 29 '18 at 09:01
  • do you have any example how to do that? – Jayson E Garcia Jun 29 '18 at 09:08
  • https://stackoverflow.com/questions/36884238/how-to-close-activity-android-using-visual-studio-and-xamarin check this https://www.google.com/search?q=how+to+finish+activity+in+xamarin+site:stackoverflow.com&client=ubuntu&hs=XvC&channel=fs&sa=X&ved=0ahUKEwjA1KKYw_jbAhVGfCsKHdS_CtYQrQIINygEMAA&biw=1598&bih=726 – AskNilesh Jun 29 '18 at 09:09
  • Thank you nilesh for giving me the information but i need to close the previous activity and not the current activity :( – Jayson E Garcia Jun 29 '18 at 09:17

1 Answers1

0

You can try to finish the current activity after starting the another activity.

FindViewById<Button>(Resource.Id.button).Click += (s, e) =>
        {
            StartActivity(typeof(SecondActivity)); // This will launch another activity.
            Finish(); // This will finish  the current activity after SecondActivity launch 
        };

The error is thrown because your are trying to close an activity that is not currently active or it may be removed from memory.

Nandha
  • 47
  • 6