My app will call startForegroundService(intent) in the onCreate of the MainActivity. And I put startForeground(ON_SERVICE_CONNEC
I experienced this issue for Galaxy Tab A(Android 8.1.0). In my application, I start a foreground service in the constructor of MainApplication(Application-extended class). With the Debugger, I found it took more than 5 second to reach OnCreate() of the service after startForegroundService(intent). I got crash even though startForeground(ON_SERVICE_CONNECTION_NID, notification) got called in OnCreate().
After trying different approach, I found one works for me as the following:
In the constructor, I used AlarmManager to wakeup a receiver, and in the receiver, I started the foreground service.
I guessed that the reason I had the issue because heavy workload of application starting delayed the creation of the foreground service.
Try my approach, you might resolve the issue as well. Good luck.