[Android] Prevent IllegalStateException in permissions fragment

Geoffrey Métais git at videolan.org
Wed Nov 29 15:17:05 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Nov 29 15:04:57 2017 +0100| [af962ea33e447a1e79bff36efdae267d812ae886] | committer: Geoffrey Métais

Prevent IllegalStateException in permissions fragment

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

 .../org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java
index 7ade4e5bc..3cf5fef25 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.java
@@ -104,10 +104,11 @@ public class StoragePermissionsDelegate extends BaseHeadlessFragment {
     }
 
     public static void askStoragePermission(@NonNull FragmentActivity activity) {
+        if (activity.isFinishing()) return;
         final FragmentManager fm = activity.getSupportFragmentManager();
-        Fragment fragment = fm.findFragmentByTag(TAG);
+        final Fragment fragment = fm.findFragmentByTag(TAG);
         if (fragment == null)
-            fm.beginTransaction().add(new StoragePermissionsDelegate(), TAG).commit();
+            fm.beginTransaction().add(new StoragePermissionsDelegate(), TAG).commitAllowingStateLoss();
         else
             ((StoragePermissionsDelegate)fragment).requestStorageAccess();
     }



More information about the Android mailing list