[Android] Avoid useless try to start the service in background

Nicolas Pomepuy git at videolan.org
Fri Jan 6 07:12:41 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jan  3 13:22:10 2023 +0100| [01728559c14b0fc9159be8ee8279512a933b0121] | committer: Nicolas Pomepuy

Avoid useless try to start the service in background

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

 .../main/java/org/videolan/resources/util/Extensions.kt    | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt b/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
index c7af8d1e93..d8a989c71c 100644
--- a/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
+++ b/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
@@ -14,7 +14,6 @@ import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.resources.*
 import org.videolan.tools.*
 import java.io.File
-import java.util.ArrayList
 import kotlin.coroutines.resume
 
 
@@ -92,15 +91,10 @@ suspend fun Context.dbExists(coroutineContextProvider: CoroutineContextProvider
 }
 
 fun Context.launchForeground(intent: Intent) {
-    try {
-        startService(intent)
-    } catch (e: IllegalStateException) {
-        //wait for the UI thread to be ready
-        val ctx = this
-        AppScope.launch(Dispatchers.Main) {
-            intent.putExtra("foreground", true)
-            ContextCompat.startForegroundService(ctx, intent)
-        }
+    val ctx = this
+    AppScope.launch(Dispatchers.Main) {
+        intent.putExtra("foreground", true)
+        ContextCompat.startForegroundService(ctx, intent)
     }
 }
 



More information about the Android mailing list