tags:

views:

43

answers:

1

I've a piece of code that launches an Intent. I'm wondering if there's any way to get return codes and/or catch exceptions? The particular scenario I'm facing is when I launch an Intent passing a 'rtsp' URL but it turns out the URL isn't available.

+1  A: 

Generally speaking no, and never really for exceptions. Note that the thing you are starting may not be in the same process as you.

Some activities support startActivityForResult(), in which case you can get some information when the launched activity finishes. However, that's usually for cases where the flow is almost dialog-esque; I would not expect a media player to necessary honor startActivityForResult().

CommonsWare
If that's the case, then how do I log something if an activity that has responded to my intent fails? I mean, sometimes users complain of something and I'd like to be able to see what's going on in the triggered activity. This is useful especially when the problem cannot be reproduced on the dev phone.
ebernie
"If that's the case, then how do I log something if an activity that has responded to my intent fails?" The docs say that you will get `RESULT_CANCELED` in `onActivityResult()` if you invoked it with `startActivityForResult()`. Otherwise, though, it is not your job to "log something", because that's not your app, any more than it is Firefox's job to "log something" if Microsoft Word chokes on a Word document opened from a link. In your specific case, if you're worried about invalid URLs, do your own `HTTP HEAD` request via `HttpClient` before launching the `Intent` to confirm the URL is OK.
CommonsWare
Guess you're right. Validation of the URL is in order anyway. Thanks for taking time to respond.
ebernie