Skip to content
Snippets Groups Projects
Commit ef27cc72 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Wait for the UI thread to be ready before starting foreground services

parent 896748d5
No related branches found
No related tags found
1 merge request!1175Fix multiple crashes
Pipeline #163833 passed with stage
in 5 minutes and 54 seconds
......@@ -93,7 +93,11 @@ fun Context.launchForeground(intent: Intent) {
try {
startService(intent)
} catch (e: IllegalStateException) {
intent.putExtra("foreground", true)
ContextCompat.startForegroundService(this, intent)
//wait for the UI thread to be ready
val ctx = this
AppScope.launch(Dispatchers.Main) {
intent.putExtra("foreground", true)
ContextCompat.startForegroundService(ctx, intent)
}
}
}
\ No newline at end of file
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