Skip to content
Snippets Groups Projects
Commit b1d58b0e authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

MediaparsingService: Ensure app is foreground

parent f6cd2b84
No related branches found
No related tags found
No related merge requests found
......@@ -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@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@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@launch
}
ctx.startMedialibrary(firstRun, upgrade, true)
if (onboarding) settings.edit().putBoolean(ONBOARDING_DONE_KEY, true).apply()
}
}.start()
val intent = Intent(this@StartActivity, if (tv) MainTvActivity::class.java else MainActivity::class.java)
.putExtra(EXTRA_FIRST_RUN, firstRun)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment