Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is logic behind before super.method or after super.method in android?

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();
        }

    }
like image 551
Mahesh Avatar asked Dec 09 '14 07:12

Mahesh


1 Answers

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...

like image 128
Leonidos Avatar answered Oct 08 '22 02:10

Leonidos