flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

App continues to crash on Android

Open zionnite opened this issue 1 year ago • 10 comments

I dont know what its wrong, after app build like within 1-3mins the app will crash immidately

i'm currently using the latest package flutter_background_service 5.0.5

D/AndroidRuntime( 5196): Shutting down VM
E/AndroidRuntime( 5196): FATAL EXCEPTION: main
E/AndroidRuntime( 5196): Process: com.com.myapp, PID: 5196
E/AndroidRuntime( 5196): android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{24f2177 u0 com.zioninvasion.prayer_buddy/id.flutter.flutter_background_service.BackgroundService}
E/AndroidRuntime( 5196): 	at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2104)
E/AndroidRuntime( 5196): 	at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2075)
E/AndroidRuntime( 5196): 	at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
E/AndroidRuntime( 5196): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2369)
E/AndroidRuntime( 5196): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 5196): 	at android.os.Looper.loopOnce(Looper.java:205)
E/AndroidRuntime( 5196): 	at android.os.Looper.loop(Looper.java:294)
E/AndroidRuntime( 5196): 	at android.app.ActivityThread.main(ActivityThread.java:8177)
E/AndroidRuntime( 5196): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5196): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime( 5196): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/AndroidRuntime( 5196): Caused by: android.app.StackTrace: Last startServiceCommon() call for this service was made here
E/AndroidRuntime( 5196): 	at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1952)
E/AndroidRuntime( 5196): 	at android.app.ContextImpl.startForegroundService(ContextImpl.java:1906)
E/AndroidRuntime( 5196): 	at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:830)
E/AndroidRuntime( 5196): 	at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:1189)
E/AndroidRuntime( 5196): 	at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:752)
E/AndroidRuntime( 5196): 	at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.start(FlutterBackgroundServicePlugin.java:82)
E/AndroidRuntime( 5196): 	at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.onMethodCall(FlutterBackgroundServicePlugin.java:121)
E/AndroidRuntime( 5196): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/AndroidRuntime( 5196): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/AndroidRuntime( 5196): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/AndroidRuntime( 5196): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/AndroidRuntime( 5196): 	at android.os.Handler.handleCallback(Handler.java:958)
E/AndroidRuntime( 5196): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 5196): 	... 6 more
I/Process ( 5196): Sending signal. PID: 5196 SIG: 9

Please how can this be fix??

zionnite avatar Jan 31 '24 07:01 zionnite

No body it's saying anything about this

zionnite avatar Feb 01 '24 06:02 zionnite

I was having these issues because i targetted SDK Version 34, by the time i downgraded it to 33 my problem was resolved

zionnite avatar Feb 01 '24 20:02 zionnite

I have the same issue if I targeting SDK Version 34. App crashes.

type: crash
processUptime: 3030 + 205 ms
installer: com.android.packageinstaller

java.lang.RuntimeException: Unable to create service com.pravera.flutter_foreground_task.service.ForegroundService: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{7432e38 29602:co..app/u11a180} targetSDK=34
 at android.app.ActivityThread.handleCreateService(ActivityThread.java:4722)
 at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2296)
 at android.os.Handler.dispatchMessage(Handler.java:106)
 at android.os.Looper.loopOnce(Looper.java:205)
 at android.os.Looper.loop(Looper.java:294)
 at android.app.ActivityThread.main(ActivityThread.java:8279)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
 at com.android.internal.os.ExecInit.main(ExecInit.java:49)
 at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
 at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359)
Caused by: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{7432e38 29602:co..app/u11a180} targetSDK=34
 at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53)
 at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
 at android.os.Parcel.readParcelableInternal(Parcel.java:4890)
 at android.os.Parcel.readParcelable(Parcel.java:4872)
 at android.os.Parcel.createExceptionOrNull(Parcel.java:3061)
 at android.os.Parcel.createException(Parcel.java:3050)
 at android.os.Parcel.readException(Parcel.java:3026)
 at android.os.Parcel.readException(Parcel.java:2968)
 at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6805)
 at android.app.Service.startForeground(Service.java:777)
 at com.pravera.flutter_foreground_task.service.ForegroundService.w(Unknown Source:306)
 at com.pravera.flutter_foreground_task.service.ForegroundService.onCreate(Unknown Source:34)
 at android.app.ActivityThread.handleCreateService(ActivityThread.java:4709)
 ... 11 more

So, for now I should use

    compileSdkVersion 34

    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 33

awaik avatar Feb 13 '24 14:02 awaik

change the compileSdkVersion to 33 and rebuild again, i too was facing this issues

On Tue, Feb 13, 2024 at 3:20 PM Alex Awaik @.***> wrote:

I have the same issue if I targeting SDK Version 34. App crashes.

type: crash processUptime: 3030 + 205 ms installer: com.android.packageinstaller

java.lang.RuntimeException: Unable to create service com.pravera.flutter_foreground_task.service.ForegroundService: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{7432e38 29602:co..app/u11a180} targetSDK=34 at android.app.ActivityThread.handleCreateService(ActivityThread.java:4722) at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2296) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8279) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) at com.android.internal.os.ExecInit.main(ExecInit.java:49) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359) Caused by: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{7432e38 29602:co..app/u11a180} targetSDK=34 at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53) at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49) at android.os.Parcel.readParcelableInternal(Parcel.java:4890) at android.os.Parcel.readParcelable(Parcel.java:4872) at android.os.Parcel.createExceptionOrNull(Parcel.java:3061) at android.os.Parcel.createException(Parcel.java:3050) at android.os.Parcel.readException(Parcel.java:3026) at android.os.Parcel.readException(Parcel.java:2968) at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6805) at android.app.Service.startForeground(Service.java:777) at com.pravera.flutter_foreground_task.service.ForegroundService.w(Unknown Source:306) at com.pravera.flutter_foreground_task.service.ForegroundService.onCreate(Unknown Source:34) at android.app.ActivityThread.handleCreateService(ActivityThread.java:4709) ... 11 more

So, for now I should use

compileSdkVersion 34

defaultConfig {
    minSdkVersion 23
    targetSdkVersion 33

— Reply to this email directly, view it on GitHub https://github.com/ekasetiawans/flutter_background_service/issues/406#issuecomment-1941623078, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACTZ2YMQWALMOML35E5BPRDYTNZDVAVCNFSM6AAAAABCSSJXWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBRGYZDGMBXHA . You are receiving this because you authored the thread.Message ID: @.***>

zionnite avatar Feb 14 '24 09:02 zionnite

there are 2 exception in this discussion:

  • MissingForegroundServiceTypeException
  • ForegroundServiceDidNotStartInTimeException

the first one could be fixed by following this or downgrading targetSdkVersion to 33 as mentioned before

the second one somehow still occured to me, but it's difficult to reproduce

nashihu avatar May 18 '24 13:05 nashihu

i have the same issue

whes1015 avatar Jul 17 '24 17:07 whes1015

change the targetSdkVersion to 33 the problem will be solved

whes1015 avatar Jul 17 '24 17:07 whes1015

Since google now required to update all the apps to target the API level 34 so downgrading is not an option now. i have fixed this issue partially as initial after updating to 34 the app is crashing as soon as launch to i have changed the AndroidManifest as per the plugin documentation .but still i am getting the following crash

android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{11916d1 u0 uat.com.toop/id.flutter.flutter_background_service.BackgroundService} E/AndroidRuntime(29357): at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2104) E/AndroidRuntime(29357): at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2075) E/AndroidRuntime(29357): at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0) E/AndroidRuntime(29357): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2369) E/AndroidRuntime(29357): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(29357): at android.os.Looper.loopOnce(Looper.java:205) E/AndroidRuntime(29357): at android.os.Looper.loop(Looper.java:294) E/AndroidRuntime(29357): at android.app.ActivityThread.main(ActivityThread.java:8177) E/AndroidRuntime(29357): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(29357): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) E/AndroidRuntime(29357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) E/AndroidRuntime(29357): Caused by: android.app.StackTrace: Last startServiceCommon() call for this service was made here E/AndroidRuntime(29357): at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1952) E/AndroidRuntime(29357): at android.app.ContextImpl.startForegroundService(ContextImpl.java:1906) E/AndroidRuntime(29357): at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:830) E/AndroidRuntime(29357): at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:1189) E/AndroidRuntime(29357): at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:752) E/AndroidRuntime(29357): at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.start(FlutterBackgroundServicePlugin.java:82) E/AndroidRuntime(29357): at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.onMethodCall(FlutterBackgroundServicePlugin.java:121) E/AndroidRuntime(29357): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/AndroidRuntime(29357): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/AndroidRuntime(29357): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/AndroidRuntime(29357): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/AndroidRuntime(29357): at android.os.Handler.handleCallback(Handler.java:958) E/AndroidRuntime(29357): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(29357): ... 6 more

bytec-D avatar Jul 18 '24 11:07 bytec-D