[Android] Improve fragments mgmt on activity restoration

Geoffrey Métais git at videolan.org
Thu Aug 24 12:16:15 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Aug 24 12:15:01 2017 +0200| [b9e0157c1c437d1995121e87090a1a209c57f0a7] | committer: Geoffrey Métais

Improve fragments mgmt on activity restoration

> https://code.videolan.org/videolan/vlc-android/commit/b9e0157c1c437d1995121e87090a1a209c57f0a7
---

 vlc-android/src/org/videolan/vlc/gui/MainActivity.java      | 13 ++++++++-----
 vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java |  1 -
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 41d9f1c5e..3866677cc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -130,18 +130,21 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
         initAudioPlayerContainerActivity();
 
         if (savedInstanceState != null) {
-            FragmentManager fm = getSupportFragmentManager();
+            final FragmentManager fm = getSupportFragmentManager();
             //Restore fragments stack
-            if (fm != null && fm.getFragments() != null)
+            if (fm != null && fm.getFragments() != null) {
+                final FragmentTransaction ft =  fm.beginTransaction();
                 for (Fragment fragment : fm.getFragments())
                     if (fragment != null) {
                         if (fragment instanceof ExtensionBrowser) {
-                            fm.beginTransaction().remove(fragment).commit();
-                        } else {
+                            ft.remove(fragment);
+                        } else if ((fragment instanceof MediaBrowserFragment)) {
                             mFragmentsStack.put(fragment.getTag(), new WeakReference<>(fragment));
-                            fm.beginTransaction().hide(fragment).commit();
+                            ft.hide(fragment);
                         }
                     }
+                ft.commit();
+            }
             mCurrentFragmentId = savedInstanceState.getInt("current", mSettings.getInt("fragment_id", R.id.nav_video));
         } else
             reloadPreferences();
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
index 6ec01f3ad..a79ddc97a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
@@ -125,7 +125,6 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
     @Override
     public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        view.setVisibility(View.VISIBLE);
         if (AndroidUtil.isJellyBeanMR1OrLater) {
             DEFAULT_BACKGROUND_DARKER_ID = UiTools.getResourceFromAttribute(view.getContext(), R.attr.background_default_darker);
             DEFAULT_BACKGROUND_ID = UiTools.getResourceFromAttribute(view.getContext(), R.attr.background_default);



More information about the Android mailing list