Manage Android Fragment Back Press Programmatically step 1: - FragmentManager fragmentManager ; (Declaration part) step 2:- fragmentManager = getFragmentManager(); fragmentManager .popBackStack( BACK_STACK_ROOT_TAG , FragmentManager. POP_BACK_STACK_INCLUSIVE ); ( onCreate ) step 3:- Add fragment on fragment manager fragmentManager .beginTransaction() .replace(R.id. framLay , fragments) .addToBackStack( BACK_STACK_ROOT_TAG ) .commit(); step 4:- back press @Override public void onBackPressed() { if ( fragmentManager .getBackStackEntryCount()> 1 ) { fragmentManager .popBackStackImmediate(); return ; } super .onBackPressed(); }
Posts
Showing posts from January, 2017