Fragment event replace?

I saw that when I execute

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
MyFragment myFragment = new MyFragment();
fragmentTransaction.replace(R.id.parent, myFragment, "MyFragment");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();

      

there is no method called old snippet. I tried:

  • OnStop ();
  • OnPause ();
  • OnDestroy ();
  • onDetach ();

No one is called, why?

+3


source to share


2 answers


Perhaps there is a typing error or a big misunderstanding in your post. At first no fragmentManager.replace()

, perhaps you meant FragmentTransaction.replace()

.

If so, try onDetach

() and onDestroy

() again. For example, make sure you have @Override attribute:



@Override
public void onDetach() {
...
}

      

+1


source


If you are going to change the checked item in the navbox I think the best way is to use the onAttachFragment

event in the main activity



0


source







All Articles