Fix crash when fast go to background

devel
Koitharu 6 months ago
parent b1b474e2e7
commit cc14e1abcf
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -1,6 +1,7 @@
package org.koitharu.kotatsu.main.ui
import android.Manifest
import android.app.BackgroundServiceStartNotAllowedException
import android.content.Intent
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.os.Build
@ -58,6 +59,7 @@ import org.koitharu.kotatsu.core.util.ext.consume
import org.koitharu.kotatsu.core.util.ext.end
import org.koitharu.kotatsu.core.util.ext.observe
import org.koitharu.kotatsu.core.util.ext.observeEvent
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
import org.koitharu.kotatsu.core.util.ext.start
import org.koitharu.kotatsu.databinding.ActivityMainBinding
import org.koitharu.kotatsu.details.service.MangaPrefetchService
@ -288,7 +290,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
adjustFabVisibility(isResumeEnabled = isEnabled)
}
private fun onFirstStart() {
private fun onFirstStart() = try {
lifecycleScope.launch(Dispatchers.Main) { // not a default `Main.immediate` dispatcher
withContext(Dispatchers.Default) {
LocalStorageCleanupWorker.enqueue(applicationContext)
@ -303,6 +305,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
}
}
}
} catch (e: BackgroundServiceStartNotAllowedException) {
e.printStackTraceDebug()
}
private fun adjustAppbar(topFragment: Fragment) {

Loading…
Cancel
Save