Considering I have a navigation view and few fragments associated with it. I wanted to end the fragment when transited to another
For example if Im in fragment A and I click fragment B (or any), The fragment A should get closed or destroyed.
Note: fragmentTransaction.replace(R.id.container, fragment);
doesn't work
code for transaction
if(fragment!=null){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.fl, fragment);
ft.commit();
}