9

I have an issue with background working of service on Samsung devices.

Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6938)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

enter image description here

Of course, after starting the service I call Service.startForeground() and there are no problems on other devices just only Samsung device.

Is anybody know the reason and how to work around of this issue?

I have found similar problem in Zopim SDK https://chat.zendesk.com/hc/en-us/community/posts/360004395368-Crash-on-Android-8-in-Android-SDK-1-4-2

Nik
  • 7,114
  • 8
  • 51
  • 75
  • probably on some devices it is taking more time before call `Service.startForeground()`, as the time betweene those 2 calls is limited – Vladyslav Matviienko Apr 12 '19 at 14:01
  • I also had the same issue but i fixed it. Please check my answer here https://stackoverflow.com/questions/55571182/service-stops-working-when-app-gets-closed/55571560#55571560. It might help you. You can also check sample code here: https://filebin.net/p5jv54ow5vl4y4gt/ServiceSample.zip?t=p6vqlepa – Ajay Mehta Apr 12 '19 at 14:02
  • are you doing any work before calling `Service.startForeground()` ? Please add your service class – Manohar Apr 19 '19 at 09:55
  • @ManoharReddy, the first call in onCreate() of service is startForeground(). Sorry, I cant show the code, it is under NDA, but it looks like ... public void onCreate() { startForeground(...) } ... – Nik Apr 19 '19 at 13:07
  • @Nik: It doesn't related to Samsung devices. As you mentioned, the problem comes from android 8 service limitations. Do you show a notification in `startForeground()`? – aminography Apr 22 '19 at 06:36
  • Just on the off-chance, does anything in this AOSP issue help? https://issuetracker.google.com/issues/76112072 – clownba0t Apr 22 '19 at 10:48
  • did you try this [https://stackoverflow.com/a/46467063/5444161] – Rahul Agrawal Apr 24 '19 at 07:06
  • Are you facing this issue in FirebaseMessagingService service? – Ganesh Pokale Apr 24 '19 at 11:12
  • @aminography of course I show notifications just after service was created – Nik Apr 29 '19 at 09:51
  • @aminography we have many thousand users, this problem happens only on samsung devices. – Nik Apr 29 '19 at 09:57

1 Answers1

0

Fixed in 1.4.4

Fixed a bug in the ChatWidgetService lifecycle handling that caused RemoteServiceException.

https://developer.zendesk.com/embeddables/docs/android-chat-sdk/releasenotes#version-1.4.4

Mikhail Sharin
  • 3,661
  • 3
  • 27
  • 36