SayWut / flutter_foreground_service_plugin

MIT License
12 stars 12 forks source link

Context.startForegroundService() did not then call Service.startForeground(): #15

Closed phantomias-kwak closed 3 years ago

phantomias-kwak commented 3 years ago

Hi,

first of all, great work, awesome package!

I am getting the following error occasionally. This is happening to some of my users, not all, mostly HUAWEI devices, some SAMSUNG.

Context.startForegroundService() did not then call Service.startForeground():

android.app.ActivityThread$H.handleMessage (ActivityThread.java:2240) android.os.Handler.dispatchMessage (Handler.java:106) android.os.Looper.loop (Looper.java:246) android.app.ActivityThread.main (ActivityThread.java:8512) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)

I have read that Android gives the application 5 seconds to call "startForeground", but from the code i do not see any issues which could cause a delay greater than 5 secs.

Never had this issue while testing, any ideas how to handle the crashes?

KR, Andreas

phantomias-kwak commented 3 years ago

This is really a bad condition which applies if the service gets STOPPED manually just after it has been STARTED. To fix this issue, just add one line in "FlutterForegroundService.java".

startForeground(1, buildNotification()); should be placed right before stopForeground(true); gets called.