소스 검색

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