瀏覽代碼

fix Android BackgroundServiceStartNotAllowedException (#687)

Fynn Petersen-Frey 2 年之前
父節點
當前提交
789bc8563c
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      mobile/android/app/src/main/kotlin/com/example/mobile/MainActivity.kt

+ 6 - 1
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
+        }
     }
 
 }