Can anyone explain me the difference between finish()
and finishActivity(int requestCode)
. And the situation of where to use them aptly.
Thanks in advance.
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
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).
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.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With