Can anyone explain me the difference between finish()
and finishActivity(int requestCode)
. And the situation of where to use them aptly.
Th
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)
Force finish another activity that you had previously started with startActivityForResult(Intent, int)
.
requestCode
The request code of the activity that you had given to startActivityForResult()
. If there are multiple activities started with this request code, they will all be finished.
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.
So basically you can call other Activities in Android from another Activity via an Intent in Android. When you call startActivityForResult, you're calling another Activity in hopes that a result of code/change in the state of your app will happen. For example, I run my Main Activity, however I call another Activity that sets various fields/variables in the app to certain values (i.e. a user setting up the app's settings). Then, when that Activity has finished and you must return to the Activity that invoked it, you may call finishActivity to send a requestCode that will flag whether the Activity invoked has performed in a way that you desired.