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

前端 未结 4 1037
失恋的感觉
失恋的感觉 2020-12-16 11:09

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

Th

相关标签:
4条回答
  • 2020-12-16 11:26

    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.

    0 讨论(0)
  • 2020-12-16 11:27

    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)

    0 讨论(0)
  • 2020-12-16 11:28

    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.

    0 讨论(0)
  • 2020-12-16 11:29

    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.

    0 讨论(0)
提交回复
热议问题