helloimyourmind
helloimyourmind

Reputation: 994

Event on fragment 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 on the old fragment. I tried with:

No one is called, why?

Upvotes: 3

Views: 5590

Answers (2)

Ebrahim Karimi
Ebrahim Karimi

Reputation: 839

If you are going to change the checked item in navigation drawer, i think the best way is to use onAttachFragment event in the main activity

Upvotes: 0

The Original Android
The Original Android

Reputation: 6215

Maybe there is a typing error in your post or a big misunderstanding. First there is no fragmentManager.replace(), perhaps you meant FragmentTransaction.replace().

If it is so, try onDetach() and onDestroy() again. Example, make sure you have the @Override attribute:

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

Upvotes: 1

Related Questions