[Android] MainActivity: clear the backstack before tab switching

Edward Wang git at videolan.org
Sun Aug 26 16:49:25 CEST 2012


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sun Aug 26 10:49:09 2012 -0400| [63b96cdc556825c96f341379298f399f4aeaaab8] | committer: Edward Wang

MainActivity: clear the backstack before tab switching

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=63b96cdc556825c96f341379298f399f4aeaaab8
---

 vlc-android/src/org/videolan/vlc/gui/MainActivity.java |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 5f2cec4..0dc2106 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -176,6 +176,16 @@ public class MainActivity extends SherlockFragmentActivity {
                 if(current.getTag() == entry.id) /* Already selected */
                     return;
 
+                /* Clear any backstack before switching tabs.
+                 * This way it's more consistent for the user, who might have
+                 * switched tabs and hit back to quit, only to activate an old
+                 * backstack.
+                 */
+                if(getSupportFragmentManager().getBackStackEntryCount() > 0) {
+                    for(int i = 0; i < getSupportFragmentManager().getBackStackEntryCount(); i++) {
+                        getSupportFragmentManager().popBackStack();
+                    }
+                }
                 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                 ft.detach(current);
                 ft.attach(mSidebarAdapter.getFragment(entry.id));



More information about the Android mailing list