Add button to clear back stack.

Change-Id: I4f02714ec349055a486608ff0eab75a46d6ba7cd
diff --git a/samples/Support4Demos/res/layout/fragment_stack.xml b/samples/Support4Demos/res/layout/fragment_stack.xml
index 1d12496..0f0951f 100644
--- a/samples/Support4Demos/res/layout/fragment_stack.xml
+++ b/samples/Support4Demos/res/layout/fragment_stack.xml
@@ -28,11 +28,19 @@
             android:layout_weight="1">
     </FrameLayout>
 
-    <Button android:id="@+id/new_fragment"
+    <LinearLayout
         android:layout_width="wrap_content" android:layout_height="wrap_content"
-        android:layout_weight="0" 
-        android:text="@string/new_fragment">
-        <requestFocus />
-    </Button>
+        android:layout_weight="0" android:orientation="horizontal">
+        <Button android:id="@+id/home"
+            android:layout_width="wrap_content" android:layout_height="wrap_content"
+            android:text="@string/home">
+            <requestFocus />
+        </Button>
+        <Button android:id="@+id/new_fragment"
+            android:layout_width="wrap_content" android:layout_height="wrap_content"
+            android:text="@string/new_fragment">
+            <requestFocus />
+        </Button>
+    </LinearLayout>
 
 </LinearLayout>
diff --git a/samples/Support4Demos/res/values/strings.xml b/samples/Support4Demos/res/values/strings.xml
index 8f70fd3..f8f4a4f 100644
--- a/samples/Support4Demos/res/values/strings.xml
+++ b/samples/Support4Demos/res/values/strings.xml
@@ -77,6 +77,7 @@
     <string name="fragment_receive_result_support">Fragment/Receive Result</string>
 
     <string name="fragment_stack_support">Fragment/Stack</string>
+    <string name="home">Go home</string>
     <string name="new_fragment">New fragment</string>
 
     <string name="fragment_tabs">Fragment/Tabs</string>
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStackSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStackSupport.java
index c4d05fa..337f2c1 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStackSupport.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStackSupport.java
@@ -20,6 +20,7 @@
 
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 
 import android.os.Bundle;
@@ -45,6 +46,17 @@
                 addFragmentToStack();
             }
         });
+        button = (Button)findViewById(R.id.home);
+        button.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                // If there is a back stack, pop it all.
+                FragmentManager fm = getSupportFragmentManager();
+                if (fm.getBackStackEntryCount() > 0) {
+                    fm.popBackStack(fm.getBackStackEntryAt(0).getId(),
+                            FragmentManager.POP_BACK_STACK_INCLUSIVE);
+                }
+            }
+        });
 
         if (savedInstanceState == null) {
             // Do first time initialization -- add initial fragment.