I have three fragment in one Activity. In second fragment i called Intent for capture image and want to save it on same fragment, but onActivityResult()
method not called.
Asked
Active
Viewed 141 times
1

RKRK
- 1,284
- 5
- 14
- 18

Snehal Jain
- 11
- 2
-
Have override _onActivityResult()_ in activity too? Also show code. – Piyush Jul 17 '19 at 06:20
1 Answers
0
just in your MainActivity
write this :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
YourFragment fragment = new YourFragment();
fragment.onActivityResult(100, resultCode, data);
}
when in your fragment have startActivityForResult(intent, 100);
above code works!
and in your fragment onActivityResult
you should do that you want.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100) {
if (resultCode == RESULT_OK && data != null) {
//do something here..
}
}
}

reyhane
- 183
- 1
- 15
-
-
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65637, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.example.isystem/com.example.isystem.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array – Snehal Jain Jul 17 '19 at 06:41
-
when in your fragment have `startActivityForResult(intent, 100);` above code work! and in your fragment `onActivityResult` you should do that you want. ( if (requestCode == 100) if (resultCode == RESULT_OK && data != null) //Do somthing here) – reyhane Jul 17 '19 at 06:47
-
-
-
Fragment A{ Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); getActivity().startActivityForResult(intent, REQUEST_CODE);} – Snehal Jain Jul 17 '19 at 08:33
-
don't write `getActivity` before `startActivityForResult`....make sure your `REQUEST_CODE ` is equals to that wrote in `onActivityResult` ( for exmple both be 100) – reyhane Jul 17 '19 at 08:39
-
If you want to check your issue, please enter your full code in the text of your question. – reyhane Jul 17 '19 at 09:34