What is the equivalent operation within an activity to navigating away from the screen. Like when you press the back button, the activity goes out of view. How can this be called from inside an activity so that it closes itself.
Asked
Active
Viewed 1.2e+01k times
5 Answers
182
What about the Activity.finish()
method (quoting) :
Call this when your activity is done and should be closed.

Pascal MARTIN
- 395,085
- 80
- 655
- 663
5
you can use finishAffinity();
to close all the activity..

DanielBarbarian
- 5,093
- 12
- 35
- 44

karthikeyan duraiswamy
- 61
- 1
- 2
3
finish() method is used to finish the activity and remove it from back stack. You can call it in any method in activity. But make sure you close all the Database connections, all reference variables null to prevent any memory leaks.

Ginni
- 136
- 1
- 2
2
You Can use just finish();
everywhere after Activity Start for clear that Activity from Stack.

raj kothiya
- 21
- 3
-
3Hi Raj, welcome to Stackoverflow. When answering questions, it's generally a good idea to check other answers to that question - someone might have already had the same idea and posted the answer! Which is exactly the case here. The top answer, and the accepted one already says `finish()` - so there isn't much to be gained for you or the community by repeating it. Sorry to be the bearer of bad news. In any case welcome to Stackoverflow, thanks for trying - hope you have better luck next time! – kenny_k Sep 17 '19 at 12:15