Add fragment to back stack

Description

When an activity goes into the background, the activity is placed in the back stack. This allows the activity to be resumed when the user presses the Back button.

Fragments are not automatically placed in the back stack when they go into the background.

Example

To place a fragment into the back stack, you need to explicitly call the addToBackStack() method during a fragment transaction.


//get the current display info
Fragment1 fragment1 = new Fragment1();
fragmentTransaction.replace(android.R.id.content, fragment1);
//add to the back stack/*from  w  w  w.j  a va2  s.  c o m*/
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();




















Home »
  Android »
    Android UI »




UI Basics
Action Bar
Animation
Button
Canvas
CheckBox
Clock Date Picker
Dialog
EditText
Event
Fragment
Gesture
GridView
ImageView
Layout
ListView
Map
Menu
Model
OpenGL
ProgressBar
RadioButton
Spinner
Tab
TextView
Thread
Toast
Video
View
WebView