[Android] MainActivity: make sure we don't accidently delete a sub-fragment
Edward Wang
git at videolan.org
Sat Aug 25 20:15:52 CEST 2012
vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sat Aug 25 14:15:18 2012 -0400| [2c98ae0cb0d46e8f7555a440792c60c2239e3781] | committer: Edward Wang
MainActivity: make sure we don't accidently delete a sub-fragment
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2c98ae0cb0d46e8f7555a440792c60c2239e3781
---
.../src/org/videolan/vlc/gui/MainActivity.java | 25 +++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 3e337a1..5f2cec4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -238,9 +238,28 @@ public class MainActivity extends SherlockFragmentActivity {
Boolean startFromNotification = getIntent().hasExtra(AudioService.START_FROM_NOTIFICATION);
/* Restore last view */
- FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- ft.replace(R.id.fragment_placeholder, mSidebarAdapter.getFragment(mCurrentFragment));
- ft.commit();
+ Fragment current = getSupportFragmentManager()
+ .findFragmentById(R.id.fragment_placeholder);
+ boolean found = false;
+ if(current != null) {
+ for(int i = 0; i < SidebarAdapter.entries.size(); i++) {
+ if(SidebarAdapter.entries.get(i).id == current.getTag()) {
+ found = true;
+ break;
+ }
+ }
+ } else {
+ found = true;
+ }
+ /* Don't call replace() on a non-sidebar fragment, since replace() will
+ * remove() the currently displayed fragment and replace it with a
+ * blank screen.
+ */
+ if(found) {
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ ft.replace(R.id.fragment_placeholder, mSidebarAdapter.getFragment(mCurrentFragment));
+ ft.commit();
+ }
if (startFromNotification)
getIntent().removeExtra(AudioService.START_FROM_NOTIFICATION);
More information about the Android
mailing list