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
  • 6,853
  • 7
  • 50
  • 74
  • 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
  • You should only use foreground service with notification on the latest versions (>8.0). – Srikar Reddy Apr 12 '19 at 14:03
  • @SrikarReddy, look at screenshot please – Nik Apr 12 '19 at 14:04
  • Share your logic right? What does "after starting the service I call Service.startForeground()" mean? Are you starting the service twice? If you started a service why call startForeground again? – Srikar Reddy Apr 12 '19 at 15:05
  • @SrikarReddy, According to docs in Android 8 and high for running Service in background mode the Service must call startForeground(). After calling startForegroundService() the system waits for startForeground() to be called within 5 seconds. If startForeground() was not called by Service, the System kills Service with exception RemoteServiceException. Of course I start my Service in background the way docs telling me. All working fine, excepting a few Samsung devices. So, I don't start my Service twice. – Nik Apr 13 '19 at 09:21
  • 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
  • Have you tried @AjayMehta-Rlogical answer, I had same problem and I had solved like Ajay Mehta said. – Faraz Ahmed Apr 25 '19 at 08:30
  • @Nik: Yes please try my solution and check if it's working for you or not. If yes so i will add the same as an answer for this question. – Ajay Mehta Apr 25 '19 at 12:14
  • @aminography of course I show notifications just after service was created – Nik Apr 29 '19 at 09:51
  • @AjayMehta-Rlogical sorry but you answer is not applicable because you show regular service usage and common rules, of course my service do all things according docs and your answer – Nik Apr 29 '19 at 09:54
  • @clownba0t it is interesting, I'll check this. – Nik Apr 29 '19 at 09:54
  • @aminography we have many thousand users, this problem happens only on samsung devices. – Nik Apr 29 '19 at 09:57
  • @Nik: Ok no problem :) – Ajay Mehta Apr 29 '19 at 09:58

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,231
  • 2
  • 25
  • 32