Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between finish() and finishActivity(int requestCode) in android

Tags:

Can anyone explain me the difference between finish() and finishActivity(int requestCode). And the situation of where to use them aptly.

Thanks in advance.

like image 559
Nireesha Avatar asked Aug 19 '11 06:08

Nireesha


People also ask

What does finish () do in Android?

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

What is finishAffinity?

finishAffinity() : finishAffinity() is not used to "shutdown an application". It is used to remove a number of Activities belonging to a specific application from the current task (which may contain Activities belonging to multiple applications).

How do you get a response from an activity in Android?

You must call the second activity using the startActivityForResult method. In your second activity, when it is finished, you can execute the setResult method where basically you put the result information. Then, on your first activity, you override the onActivityResult method.


2 Answers

finish() Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().

finishActivity(int requestCode) is used to finish another activity that you had previously started with startActivityForResult(Intent, int)

like image 176
Vineet Shukla Avatar answered Oct 15 '22 11:10

Vineet Shukla


Read Following:

public void finish ()

Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().

public void finishActivity (int requestCode)

Force finish another activity that you had previously started with startActivityForResult(Intent, int).

For further reading have a look at the documentation.

like image 37
Naveed Avatar answered Oct 15 '22 12:10

Naveed