onActivityResult not call in the Fragment
The reason why this doesn't work is because you are calling startActivityForResult()
from within a nested fragment. Android is smart enough to route the result back to an Activity
and even a Fragment
, but not to a nested Fragment
hence why you don't get the callback.
(more information to why that doesn't work here or on stackoverflow)
Now in order to make it work I suggest you manually route the callback to the ChildFragment
(=UploadType
) in the ParentFragment
(=BaseContainerFragment
):
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Fragment uploadType = getChildFragmentManager().findFragmentById(R.id.container_framelayout);
if (uploadType != null) {
uploadType.onActivityResult(requestCode, resultCode, data);
}
super.onActivityResult(requestCode, resultCode, data);
}
In my case, I've done by adding following code in my MainActivity.java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
fragment.onActivityResult(requestCode, resultCode, data);
}
}
In your Activity Override onActivityForResult() like this
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
Now in your fragment u can get the activity result inside this
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("test1", "result2");
}
Make sure when your are calling start ActivityForResult in your frragment it should be like this
startActivityForResult(intent, REQUEST_CAMERA);