Reputation: 12762
There seem to be (at least) two ways to send Intents in Android:
Other than the fact that the latter only works starting API level 5 and that the results are passed back in a different way (via PendingIntent.OnFinished
vs. Activity.onActivityResult(...)
) is there any fundamental difference between the two?
I find the first one a lot more convenient as it can be entirely encapsulated inside a library without requiring the calling activity to override onActivityResult(...)
to forward the result (like this: yuck!). Is it ok to still use that approach?
A quick clarification, because I've seen someone complain about this on another question: The methods above are not static methods. I wrote them that way simply for readability.
Upvotes: 2
Views: 645
Reputation: 12762
Seems like these two approaches are very different:
start...forResult(...)
methods start an intent or sub-activity in a way that allows for a result to be returned to the activity that executed the start...forResult(...)
. The result will be passed back to the activity's onActivityResult(...)
method.PendingIntent.send(...)
) act in a fire-and-forget-manner and don't allow for any results to be returned. The OnFinished
handler is called as soon as the launch is sent, whether or not it takes a while to complete. The data passed into this handler, therefore, does not necessarily have anything to do with what you would otherwise receive via onActivityResult(...)
. In fact, in my case, the OnFinished
handler is always called right away, before the dialog of the sub-activity even shows up, with a resultCode
of Activity.RESULT_CANCELED
.What a mess...
Upvotes: 2