Android - How to end a fragment

In my application, I have a navigation box, and how my application works, there is only one action, and if you select something from the navigation box, it will start / replace the current fragment. How can I do this so that when something is selected in the navigation box, and a new fragment starts the completion of the old fragment

I can not do

@Override public void onPause() { // TODO Auto-generated method stub super.onPause(); getActivity().finish(); } 

because it will kill the application as there is only one action.

How to kill a fragment?

EDIT: my fragment transaction

 Home HomeFragment = new Home(); transaction.replace(R.id.llhome, HomeFragment); transaction.addToBackStack(null); transaction.commit(); mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); 

thanks

+4
source share
2 answers

Just call:

 getActivity().onBackPressed(); 
+5
source

If you use dynamic fragments, configure using FragmentTransaction , you can start the transaction on replace() old fragment with the new one.

+1
source

Source: https://habr.com/ru/post/1487368/


All Articles