From 789bc8563c2646060cacafb4f99e2c41806eab05 Mon Sep 17 00:00:00 2001 From: Fynn Petersen-Frey Date: Wed, 14 Sep 2022 03:12:31 +0200 Subject: [PATCH] fix Android BackgroundServiceStartNotAllowedException (#687) --- .../app/src/main/kotlin/com/example/mobile/MainActivity.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mobile/android/app/src/main/kotlin/com/example/mobile/MainActivity.kt b/mobile/android/app/src/main/kotlin/com/example/mobile/MainActivity.kt index f16acc394..2e6372231 100644 --- a/mobile/android/app/src/main/kotlin/com/example/mobile/MainActivity.kt +++ b/mobile/android/app/src/main/kotlin/com/example/mobile/MainActivity.kt @@ -14,7 +14,12 @@ class MainActivity: FlutterActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - startService(Intent(getBaseContext(), AppClearedService::class.java)); + try { + startService(Intent(getBaseContext(), AppClearedService::class.java)); + } catch (e: Exception) { + // startService must not be called when app is in background (crashes app) + // there is nothing we can do + } } }