You must specify the TAG when adding / replacing:
ft.replace(R.id.container, newFragment,"fragment_tag_String");
OR
ft.add(R.id.container, newFragment,"fragment_tag_String");
Add the snippet to BackStack as:
ft.addToBackStack("fragment_tag_String");
Then you can reuse it with
getSupportFragmentManager().findFragmentByTag("fragment_tag_String");
Contact:
Edit:
Call getSupportFragmentManager().executePendingTransactions()
after transaction
FragmentManager fm = MainActivity.this.getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.activity_main_content_fragment, fragment, text); ft.commit(); fm.executePendingTransactions();
Hope this helps you.
source share