Difference between startActivityForResult() and startActivity()? [closed]
Asked Answered
C

2

51

What is the difference between startActivityForResult() and startActivity() ?

When, and for what, should I use each one ?

Contour answered 2/1, 2013 at 9:59 Comment(3)
Read Before Ask Question. developer.android.com/reference/android/app/Activity.htmlSavina
startActivity() simply starts an activity. startActivityForResult() starts an activity and return the generated result in onActivityResult() method of calling activityDneprodzerzhinsk
check this link saiful103a.wordpress.com/2011/03/19/…Regiment
M
43

startActivity

Start an activity, like you would start an application: for instance: you have an app with a home-screen and a user-info screen: if you press the user-info button, you start the user-info activity with this.

startActivityForResult

Start an activity and expect something in return. For instance, on your user-info screen, you can upload a profile picture. You start the gallery-activity with the explicit goal to get a URI back with the preferred picture. You start this activity literaly to obtain a result (the picture. There are some techinical ways to make sure you actually get the result, but they are quite clear in the manual.

Moxley answered 2/1, 2013 at 10:3 Comment(0)
R
30

startActivity will start a new activity and not care when where and how that activity finishes.

evidently

startActivityForResult waits for callbacks when the started activity decided to finish

startActivity() will start the activity you want to start without worrying about getting any result from new child activity started by startActivity to parent activity.

startActivityForResult() starts another activity from your activity and it expect to get some data from newly started child activity by startAcitvityForResult() and return that to parent activity.

Check this link - Activity#startActivityForResult(Intent, int)

Regiment answered 2/1, 2013 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.