5

My app has a service that extends the class JobIntentService from AppCompat to process some data on device and post it to a HTTPs address.

The code is very simple, as any sample provided on internet/documentation:

How I call the JobIntentService?

(I call this from FirebaseMessagingService)

val intent = Intent()
intent.putExtra(SOME_INFO, data["someInfo"]?.toInt() ?: INVALID_VALUE_INT)
MyCoolService.enqueueWork(applicationContext, intent)

How the JobIntentService looks like?

class MyCoolService: JobIntentService() {

  companion object {
    val JOB_ID = 1001
    fun enqueueWork(context: Context, work: Intent) {
      enqueueWork(context, MyCoolService::class.java, JOB_ID, work)
    }
  }

  override fun onHandleWork(intent: Intent) {
    //Heavy work here... or empty, doesn't matter... The error happens too.
  }

}

Manifest:

<uses-permission android:name="android.permission.WAKE_LOCK"/>

<application
  android:allowBackup="true"
  android:fullBackupContent="true"
  ...>

  <service android:name="com.my.app.MyCoolService"
      android:label="some info service"
      android:exported="false"
      android:permission="android.permission.BIND_JOB_SERVICE"/>

<application>

Logcat:

19701-19715/com.my.app I/zygote64: Thread[3,tid=19715,WaitingInMainSignalCatcherLoop,Thread*=0x7fa16c0400,peer=0x16400088,"Signal Catcher"]: reacting to signal 3
19701-19715/com.my.app E/zygote64: # HandleSigQuit # DumpForSigQuit # before # pid=19701
19701-19715/com.my.app E/zygote64: # HandleSigQuit # DumpForSigQuit # after # pid=19701
19701-19715/com.my.app I/zygote64: Wrote stack traces to '/data/anr/traces.txt'
19701-19701/com.my.app D/AndroidRuntime: Shutting down VM
19701-19701/com.my.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.my.app, PID: 19701
    android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6809)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

_

Cool! the log say to me to add Service.startForeground(), crash too.

Misc:

ANDROID_BUILD_TOOLS_VERSION=26.0.2
ANDROID_COMPILE_SDK_VERSION=27
KOTLIN_VERSION=1.2.20
APP_COMPAT_VERSION=27.0.1

I was able to reproduce this on a One Plus 3T @ 8.0.0 and Nexus 5X @ 8.1.

Any ideia why this is happening? Thanks!

EDIT 1:

Calling this JobIntentService from an Activity or Service does not crash.

EDIT 2:

firebase-core: 11.8.0

Pedro Paulo Amorim
  • 1,838
  • 2
  • 27
  • 50
  • any update on this? – Kalai.G Jul 18 '18 at 15:33
  • did you find a fix, am facing the same, but for GCM messaging – Mal Nov 20 '18 at 00:10
  • Curious about the reason the log stated that `startForegroundService` was called without the other method call following. Are you 100% sure you aren't calling inadvertently `startForegroundService`? Usage of `JobIntentService` is meant to be an alternative to starting services as foreground explicitly – Jose_GD Nov 20 '18 at 21:07
  • https://stackoverflow.com/questions/44425584/context-startforegroundservice-did-not-then-call-service-startforeground That one seem similar, have you checked out the first answer? – Adam Feb 12 '19 at 12:33

0 Answers0