[Android] MediaparsingService: Ensure app is foreground
Geoffrey Métais
git at videolan.org
Mon Jan 27 16:52:14 CET 2020
vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan 27 16:09:56 2020 +0100| [b1d58b0ea48787c2ba3c0ceb2ec148a0d0661e7c] | committer: Geoffrey Métais
MediaparsingService: Ensure app is foreground
> https://code.videolan.org/videolan/vlc-android/commit/b1d58b0ea48787c2ba3c0ceb2ec148a0d0661e7c
---
vlc-android/src/org/videolan/vlc/StartActivity.kt | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/StartActivity.kt b/vlc-android/src/org/videolan/vlc/StartActivity.kt
index 72e5e90f8..0295f9286 100644
--- a/vlc-android/src/org/videolan/vlc/StartActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/StartActivity.kt
@@ -178,12 +178,20 @@ class StartActivity : FragmentActivity(), CoroutineScope by MainScope() {
private fun startApplication(tv: Boolean, firstRun: Boolean, upgrade: Boolean, target: Int) {
val settings = Settings.getInstance(this at StartActivity)
val onboarding = !tv && !settings.getBoolean(ONBOARDING_DONE_KEY, false)
+ val ctx = applicationContext
// Start Medialibrary from background to workaround Dispatchers.Main causing ANR
// cf https://github.com/Kotlin/kotlinx.coroutines/issues/878
if (!onboarding || !firstRun) {
Thread {
- this at StartActivity.startMedialibrary(firstRun, upgrade, true)
- if (onboarding) settings.edit().putBoolean(ONBOARDING_DONE_KEY, true).apply()
+ AppScope.launch {
+ // workaround for a Android 9 bug
+ // https://issuetracker.google.com/issues/113122354
+ if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P && !awaitAppIsForegroung()) {
+ return at launch
+ }
+ ctx.startMedialibrary(firstRun, upgrade, true)
+ if (onboarding) settings.edit().putBoolean(ONBOARDING_DONE_KEY, true).apply()
+ }
}.start()
val intent = Intent(this at StartActivity, if (tv) MainTvActivity::class.java else MainActivity::class.java)
.putExtra(EXTRA_FIRST_RUN, firstRun)
More information about the Android
mailing list