Skip to content Skip to sidebar Skip to footer

Onactivityresult Not Called In Fragment Android

This is my code to take picture from gallery. public class FragmentLayout1 extends Fragment implements OnClickListener { View root; Context c; Button add_image; D

Solution 1:

Make sure you call startActivityForResult() and not getActivity().startActivityForResult() from your fragment. refer onActivityResult is not being called in Fragment

Solution 2:

Override onActivityResult in parent Activity i.e. parent of all fragment

Solution 3:

If you are overriding onActivityResult in your Activity then make sure you do call super.onActivityResult there too in order to propagate the result to your fragments.

Solution 4:

Also if you call startActivityForResult() from your fragment, then onActivityResult() will be called in your fragment. And if you call startActivityForResult() from your activity, then onActivityResult() will be called in your activity. Basically where you call startActivityForResult() is where onActivityResult() will be called.

Another thing, in Android the prefered way to create dialogs is to extend the DialogFragment class.

Solution 5:

Issue is very sensitive and little tricky the observation(fix) i have made for this as follows,

When u called Activity B from Activity A the source activity(A) instance should be in stack(memory) to invoke "onActivityResult" callback.

The issue explained with reason below,

Observation: From Material design back and NavUtils.navigateUpFromSameTask - the description of navigateUpFromSameTask as follows "Convenience method that is equivalent to calling navigateUpTo(sourceActivity, getParentActivityIntent (sourceActivity)). sourceActivity will be finished by this call"

remember sourceActivity (A) is removed from stack(memory) when used this method.

when there is no sourceActivity(A) no base instance(A) left to invoke "onActivityResult" callback.

Post a Comment for "Onactivityresult Not Called In Fragment Android"