user2349832
user2349832

Reputation: 3

How to open intent and add value android

I have trouble with returning a value to another intent in android. This is my situation: I have Activity A, which is opened when I start my application. When I click on a button I start Activity B. In activity B I fill in a EditText and return a string. Then I click on a button in activity B to return to activity A. I don't know what method I should use in activity A to use the value I get returned from activity B.

Upvotes: 0

Views: 93

Answers (2)

Blackbelt
Blackbelt

Reputation: 157437

this kind of situation fits good for startActivityForResult and onActivityForResult. When you press on the button, instead of calling startActivity you call startActivityForResult in order to start ActivityB. In ActivityB when you click on the button, you have to fill up an Intent with the values you want to return to ActivityA and, in order, call setResult(result, Intent) and finish(). The onActivityResult of ActivityA will receive the intent with your data

Activity Docs

Upvotes: 1

Anirudh
Anirudh

Reputation: 389

You should start activity B by calling startActivityForResult() instead of startActivity() and on Activity B, in your exit button click listener, setResult() results to pass to Activity A.

You can handle the result by overriding onActivityResult() method in Activity A

Check this : http://developer.android.com/reference/android/app/activity.html Search for "Starting Activities and Getting Results"

Upvotes: 0

Related Questions