Hello everyone i want to ask what is difference between if i something write before super.onDestroyView(); and after super.onDestroyView(); see example below
Remove fragment before super.ondestoryview();
@Override
public void onDestroyView() {
try {
Fragment fragment = (getFragmentManager()
.findFragmentById(R.id.mapviews));
FragmentTransaction ft = getActivity().getSupportFragmentManager()
.beginTransaction();
ft.remove(fragment);
ft.commit();
} catch (Exception e) {
e.printStackTrace();
}
super.onDestroyView();
}
Remove fragment after super.ondestoryview();
@Override
public void onDestroyView() {
super.onDestroyView();
try {
Fragment fragment = (getFragmentManager()
.findFragmentById(R.id.mapviews));
FragmentTransaction ft = getActivity().getSupportFragmentManager()
.beginTransaction();
ft.remove(fragment);
ft.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
If super was Fragment, than there is no difference how you do it, because Fragment's onDestroyView does nothing. But in some cases it matters.
As Dianne Hackborn said:
general rule: during any kind of initialization, let the super class do their work first; during any kind of finalization, you do your work first
P.S. IMHO it's not a good solution to remove fragment from other Fragment's onDestroyView method. That's strange, I think you should find better place for managing your fragments...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With