[Android] StorageBrowser: Prevent IllegalStateException

Geoffrey Métais git at videolan.org
Wed Mar 6 15:43:05 CET 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar  1 15:56:52 2019 +0100| [006f35f774adb2accc3d33dee98bdef73b630d07] | committer: Geoffrey Métais

StorageBrowser: Prevent IllegalStateException

(cherry picked from commit 5f94a252e810c362a95a627be38ca1e60a06b96d)

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

 .../src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt      | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
index a0b588c3e..a1346cd27 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
@@ -106,7 +106,7 @@ class StorageBrowserFragment : FileBrowserFragment(), EntryPointsEventsCb, Corou
     }
 
     override fun onRestart() {
-        launch { (adapter as StorageBrowserAdapter).updateListState(requireContext()) }
+        launch { if (isAdded) (adapter as StorageBrowserAdapter).updateListState(requireContext()) }
     }
 
     override fun onStop() {
@@ -151,9 +151,9 @@ class StorageBrowserFragment : FileBrowserFragment(), EntryPointsEventsCb, Corou
     override fun onCtxClick(v: View, position: Int, item: MediaLibraryItem) {
         if (isRootDirectory) {
             val storage = adapter.getItem(position) as Storage
-            coroutineScope.launch {
+            launch {
                 val isCustom = viewModel.customDirectoryExists(storage.uri.path)
-                if (isCustom) showContext(requireActivity(), this at StorageBrowserFragment, position, item.title, CTX_CUSTOM_REMOVE)
+                if (isCustom && isAdded) showContext(requireActivity(), this at StorageBrowserFragment, position, item.title, CTX_CUSTOM_REMOVE)
             }
         }
     }



More information about the Android mailing list