1'hafs
1'hafs

Reputation: 579

OnActivityResult not triggered inside Fragment

I'm calling ACTION IMAGE CAPTURE intent from a fragment, and I've implemented the onActivityResult() in same fragment but the onActivityResult is not triggered while running it with my note2 device. Check the code snippets below that I used.

It worked fine when I am not using

 import android.support.v4

Upvotes: 1

Views: 1098

Answers (1)

MH.
MH.

Reputation: 45503

I'm calling ACTION IMAGE CAPTURE intent from a fragment (...)

That's not quite true. Look at the following line of code:

getActivity().startActivityForResult(SaveCardFragment.this,intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

Key to notice is that you call startActivityForResult() on the hosting activity (HomeActivity), not the fragment (SaveCardFragment), hence the result is delivered to the activity and not propagated any further. If you want the result to be delivered to the fragment, ensure you call startActivityForResult() on the fragment. In other words, just get rid of the getActivity() prefix:

startActivityForResult(SaveCardFragment.this,intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

See: Fragment#startActivityForResult

Upvotes: 1

Related Questions