[Android] Get correct currently displayed fragment

Geoffrey Métais git at videolan.org
Wed Sep 13 13:44:41 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Sep 13 13:20:47 2017 +0200| [4f4ca9f0978b8d456ba69cca5a522857cbc7a5d8] | committer: Geoffrey Métais

Get correct currently displayed fragment

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

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

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 68976086d..30da1b9e0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -702,8 +702,14 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
 
     protected Fragment getCurrentFragment() {
         return mCurrentFragment instanceof BaseBrowserFragment || currentIdIsExtension()
-                ? getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder)
-                : mCurrentFragment;
+                ? getFirstVisibleFragment() : mCurrentFragment;
+    }
+
+    private Fragment getFirstVisibleFragment() {
+        for (Fragment fragment : getSupportFragmentManager().getFragments())
+            if (!fragment.isHidden() && fragment.getClass().isInstance(mCurrentFragment))
+                return fragment;
+        return mCurrentFragment;
     }
 
     public boolean currentIdIsExtension() {



More information about the Android mailing list