katit katit - 4 months ago 51
Android Question

Custom View calling startActivityForResult

I created custom compound view where I incorporate functionality to take pictures.

I'm calling it like this (from view):

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
((Activity)mContext).startActivityForResult(intent, index);

This part works good. What I don't know how to do is how do I implement


Inside my custom view?

Or should I catch this inside Activity and than re-route into my view? Doesn't look like very nice solution..


There is no way to catch onActivityResult from your view, only from Activity.

And its not safe to assume that's Context object is Activity. In general you should not rely on this fact. Even if it seems reasonable in case with views, you still should use only methods available trough Context interface. That's because your can't predict all side-effects on the Activity, when you're calling Activity specific functions.