i've written an activity with three fragments. PlantFragment.java is the main fragment that has a floating button to select a farmer. This FAB starts a fragment FarmersSelectorFragment.java which gives a list of farmers and on selecting one, it pops from the stack returning a result to the PlantFragment.java. Then i want to start another Fragment when the result is ok. The FarmersSelectorFragment.java returns the farmer selected, however starting the next fragment fails with nothing happening. How can i start a new Fragment when a result is returned.
PlantFragment.java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CODE) {
Fragment fragment = new PlantAddFragment();
fragment.setArguments(data.getBundleExtra("bundle"));
getFragmentManager().beginTransaction()
.replace(((ViewGroup) getView().getParent()).getId(), fragment)
.addToBackStack(null)
.commit();
}
}
}
I managed to pick the returned data on result however (ViewGroup) getView().getParent()).getId() throws a null pointer in the onActivityResult