There is a program that uses DrawerLayout, in which fragments are loaded from the menu (depending on where the user clicks).
The fragment download code itself is as follows:
public void loadFragment(Fragment fragmentTarget, String title) { if (fragmentTarget == null){ return; } Log.d(TAG, "load fragment " + title); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.content_frame); if (fragment == null){ fm.beginTransaction().add(R.id.content_frame, fragmentTarget).commit(); } else { fm.beginTransaction().replace(R.id.content_frame, fragmentTarget) .addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit(); } title = getString(R.string.app_name) + " " + title; getSupportActionBar().setTitle(title); Actually the question: How to avoid the situation that the user clicking the same menu item twice in a row does not reload the fragment (the reload itself is not so terrible, but the fact that this fragment is added to the stack is not very good in terms of usability)
update I can of course keep the name of the current fragment loaded in the main activity in a variable, but it seems to me that it is not quite right
fm.beginTransaction().add. Alwaysfm.beginTransaction().replace. This is essentially the design of the DrawerLayout pattern - pavel163