android - how to back to previous fragment on pressing manually back button -
A activity and many pieces I have in my app I i when a button suppresses back all the pieces
I used this code segment but after pressing the back button it came once again for no major activity. Also I want to change the icon, when it comes to the main activity. (Msg_alert)
btnBack.setOnClickListener (New OnClickListener () {@Override see public void onClick (v) {FragmentManager FM = MainActivity.this .getSupportFragmentManager (); FragmentTransaction ft = fm.beginTransaction ( ); piece = new MainMenuLayout (); ft.replace (R.id.activity_main_content_fragment, piece); Ftkcommit (); BtnBackksetVisibility (see. visual); Bitianbakksetaimejarsosar (Ardrovabl.ammsjielrt); T Vititl. Settext ("layout 0");}}); Let's say that you have two pieces A and B is attached on the piece A
Visit the piece B on a piece of activity and startup you on any user event. Use
1) the activity of piece add B
works with // either Framework fragment manager / support package Fragment Manager (getSupportFragmentManager). . GetSupportFragmentManager () beginTransaction () .replace (R.id.container, fragmentB, "detail") // this deal back stack .addToBackStack (pairs) .commit (in);
2) OnBackPressed override of activity to handle back button press event.
@override public void onBackPressed () {// there piece in any stack, if yes popout that (getSupportFragmentManager (). GetBackStackEntryCount () & gt; 0) {getSupportFragmentManager (). PopBackStack (); Return; } Super.onBackpressed (); }
Comments
Post a Comment