user2738859
user2738859

Reputation: 31

How can I stop repeating backing?

I'm developing an application with more than 3 classes. My app is working like this:

I jumped from main activity to another class and then to 3-rd class and came back to 2-nd class and then to 3-rd class again.

My problem was when I pressed the back button when I was in 3-rd it went to 2-nd and then to 3-rd and came again to 2-nd then to 1-st then to home.

I want to stop this process.

Upvotes: 1

Views: 71

Answers (2)

yushulx
yushulx

Reputation: 12160

I think the problem is when you came back to second class from third class, you didn't destroy third class instance. Probably you just started a new Activity, like startActivity(second class). Every time you switched to another class, you create a new Activity instance without destroy previous one. Doing this repeatedly, many Activity instances were kept in task stack. If you don't wanna repeat, you have to destroy previous activity, or change your implementation. You can create a customized stack by yourself, and add or remove Class instances as a view not activity. so 1->(add)2->(add)3->(remove 3)2->(add)3->(remove 3)2->(remove 2)1.

Upvotes: 1

pepe-pa
pepe-pa

Reputation: 552

Use finish() in onStop() method

Upvotes: 0

Related Questions