I have two fragments with names F1 and F2 and an activity named A.
I added fragment F1 in a Framelayout
inside activity A using something like this:
F1 fragment = new F1();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.main_drawer_frame, F1, LEFT_DRAWER_FRAGMENT);
transaction.commit();
Then inside fragment F1 I added fragment F2 in another layout:
F2 fragment = new F2();
fragment.setTargetFragment(this, 0); //"this" refer to an instance of F1
FragmentTransaction transacton = getChildFragmentManager().beginTransaction();
transacton.replace(R.id.drawer_host_frame, fragment, CURRENT_FRAGMENT);
transacton.commit();
Then I start an Activity from F2 using startActivityForResult()
:
startActivityForResult(getActivity(), intent, REQUEST_ACCOUNT);
And then I overrided onActivityResult()
inside fragment F2. but the problem is onActivityResult() is never called. then I figured out that super.onActivityResult()
inside fragment F1 don't trigger onActivtyResult()
inside fragment F2.
I can manually retrieve every Fragment inside getChildFragmentManager() and then call onActivityResult()
on them, but its clumsy and is like I'm just leaving the real problem unsolved.