0

i am facing this issue in service running on background. It will automatic crash in background. Where is the issue i couldn't find out.

Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): 
ServiceRecord{e4c7ef5 u0 com.clap.find.my.mobile.alarm.sound/.service.BatteryAlertService}
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2137)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:7948)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
vasu
  • 1
  • 2

1 Answers1

1

kindly refer to this link and you will definitely know what going on and reason for your crash .

read this

if you can opt below criteria then u can probably solve your fix .

Why this issue is happening is because Android framework can't guarantee your service get started within 5 second but on the other hand framework does have strict limit on foreground notification must be fired within 5 seconds, without checking if framework had tried to start the service.

This is definitely a framework issue, but not all developers facing this issue are doing their best:

  1. startForeground a notification must be in both onCreate and onStartCommand, because if your service is already created and somehow your activity is trying to start it again, onCreate won't be called.
  2. notification ID must not be 0 otherwise same crash will happen even it's not same reason.
  3. stopSelf must not be called before startForeground.

With all above 3 this issue can be reduced a bit but still not a fix, the real fix or let's say workaround is to downgrade your target sdk version to 25.**

Nikit Dungrani
  • 185
  • 1
  • 7