Android Closing Activity Programmatically

AndroidAndroid Activity

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

What about the Activity.finish() method (quoting) :

> Call this when your activity is done > and should be closed.

Solution 2 - Android

you can use this.finish() if you want to close current activity.

this.finish()

Solution 3 - Android

you can use finishAffinity(); to close all the activity..

Solution 4 - Android

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.

Solution 5 - Android

You Can use just finish(); everywhere after Activity Start for clear that Activity from Stack.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndroiderView Question on Stackoverflow
Solution 1 - AndroidPascal MARTINView Answer on Stackoverflow
Solution 2 - AndroidSoheilView Answer on Stackoverflow
Solution 3 - Androidkarthikeyan duraiswamyView Answer on Stackoverflow
Solution 4 - AndroidGinniView Answer on Stackoverflow
Solution 5 - Androidraj kothiyaView Answer on Stackoverflow