In my Android app, I start a new activity with startActivityForResult()
. I get the result in onActivityResult()
perfectly. My problem is that there is a small bit of data that I know before I start the activity and I need that value to be available in onActivityResult()
, too. I tried attaching it to my intent as an extra, but it wasn't attached to the intent that is available when the activity returns the result. I made it work by storing the data in a global variable, but I really don't like that approach. Is there a better, right way to pass data through an activity (instead of just to it)?
views:
121answers:
1
A:
You can use setResult(int,Intent) to give data back to onActivityResult(), passing in the same intent you were given (although some of it's properties, like the action or uri, will be useless).
You can use this to build up data between two activities, with one supplying the information it knows about and the other filing in the rest and returning when it is called.
sargas
2010-06-29 21:56:41
The Activity that I'm calling is a standard Android one (shows the contact list so the user can select one). Is there a way to do this with Activities I didn't create?
Daedylus
2010-06-30 16:27:15
@Daedylus, Ofcourse! :) It's the same way as sargas mentions:)
st0le
2010-10-31 04:58:00