Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Closing Activity Programmatically

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.

like image 700
Androider Avatar asked Feb 27 '11 16:02

Androider


People also ask

How do you end an activity?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.

How do you stop a Java activity?

Use finish(); in Activity class to stop Activity and return.

How do I close an activity from another activity?

In Activity [A], on button click, I am calling Activity [B] without finishing Activity [A]. Now in Activity [B], there are two buttons, New and Modify. When the user clicks on modify then pop an activity [A] from the stack with all the options ticked..

How do I close a programmatically app in Android?

use 'System. exit(0);' when you really want to exit the app.


2 Answers

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

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

like image 111
Pascal MARTIN Avatar answered Oct 19 '22 03:10

Pascal MARTIN


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

this.finish() 
like image 38
Soheil Avatar answered Oct 19 '22 05:10

Soheil