Ahmed Mujtaba
Ahmed Mujtaba

Reputation: 2248

How to kill activity on back button press

I have a small issue in my android app. I want to kill the current activity when the back button is pressed. I have included this in my code:

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

But the activity doesn't finish when I go back to the previous page. I have an external callback method in this activity that is called even when I'm not on this activity. The method get's called as many times as I open the activity so I figured the activity is not getting closed properly. For example the method (SignalR callback) doesn't get called when I don't open the activity but as I open and close it, the method keeps getting called the number of times I opened and closed the activity when ever there a function callback. Does anyone have any idea why this is happening?

Upvotes: 0

Views: 407

Answers (1)

Karakuri
Karakuri

Reputation: 38595

You can unsubscribe your callback in onStop()

Upvotes: 1

Related Questions