In the Activity class:
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode,resultCode,data); }
In the fragment:
@Override public void onActivityResult(int requestCode, int resultCode, Intent data){}
Option 1:
If you call startActivityForResult() from the fragment, you should call startActivityForResult() not getActivity().startActivityForResult() , as this will result in the onActivityResult() fragment.
If you donβt know where you are calling startActivityForResult() and how you will call methods.
Option 2:
Since Activity gets the result of onActivityResult() , you need to override the onActivityResult() action and call super.onActivityResult() to propagate to the corresponding fragment for raw result codes or for all.
If the above 2 options do not work, refer to option 3, as this will definitely work.
Option 3:
An explicit call from the fragment to the onActivityResult function as follows
In the parent activity class, override the onActivityResult() method and even override it in the fragment class and call it as the following code.
In action:
@Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {Snippet fragment = getSupportFragmentManager (). FindFragmentById ("yourFragment"); fragment.onActivityResult (requestCode, resultCode, data); }
In the fragment:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Arslan sohail
source share