[Android] BrowserProvider: control browser in background

Geoffrey Métais git at videolan.org
Fri Jul 19 11:54:01 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jul 19 11:53:07 2019 +0200| [46436f0d25cbd278e4405073c635ad5e73e5327c] | committer: Geoffrey Métais

BrowserProvider: control browser in background

Prevents ANR

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

 vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index b88bde5bb..031c7627f 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -64,8 +64,10 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
 
     private val completionHandler : CompletionHandler = object : CompletionHandler {
         override fun invoke(cause: Throwable?) {
-            mediabrowser?.release()
-            mediabrowser = null
+            launch(Dispatchers.IO) {
+                mediabrowser?.release()
+                mediabrowser = null
+            }
             if (this at BrowserProvider::browserChannel.isInitialized) browserChannel.close()
         }
 
@@ -77,7 +79,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
             BrowseRoot -> browseRootImpl()
             Refresh -> refreshImpl()
             ParseSubDirectories -> parseSubDirectoriesImpl()
-            ClearListener -> mediabrowser?.changeEventListener(null)
+            ClearListener -> withContext(Dispatchers.IO) { mediabrowser?.changeEventListener(null) }
         }
     }
 



More information about the Android mailing list