I have searched for solutions about my problem but didn't find something that match exactly my project configuration. So let's me explain you.
I have a MainActivity that contains NavigationView. The MainActivity contains a MainActivityFragment - via NavigationView, I wish you understand exactly what I want to say. It's the default and the only one Fragment accessible directly from MainActivity.
Here's how I show MainActivityFragment in MainActivity:
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content, new MainActivityFragment()).commit();
When clicking on a Navigation Menu Item, it will show a DialogFragment:
if (id == R.id.nav_add_poi) {
new AddPoiFragment().show(getSupportFragmentManager(), AddPoiFragment.TAG);
} else if (id == R.id.nav_report_event) {
new AddEventFragment().show(getSupportFragmentManager(), AddEventFragment.TAG);
}
The MainActivityFragment contains a ViewPager with four fragments.
In AddPoiFragment (a DialogFragment), the user can take a photo. Here's how I manage the onActivityResult stuff:
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
Toast.makeText(getActivity(), "Hello", Toast.LENGTH_SHORT).show();
}
}
It seems that onActivityResult is never triggered. I have tried with getActivity().startActivityForResult()
following some other solutions but as I have said, these solutions don't match exactly my configuration and I get errors when using them.