JobIntentService在Android 8上崩溃

时间:2018-01-26 14:53:18

标签: service kotlin android-appcompat android-8.0-oreo

我的应用程序有一项服务,它从AppCompat扩展类JobIntentService以处理设备上的一些数据并将其发布到HTTPs地址。

代码非常简单,就像互联网/文档中提供的任何样本一样:

我如何致电JobIntentService

(我从FirebaseMessagingService打电话给

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

JobIntentService的样子如何?

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.
  }

}

清单:

<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)

_

酷!日志告诉我添加Service.startForeground(),也崩溃了。

其他:

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

我能够在One Plus 3T @ 8.0.0和Nexus 5X @ 8.1上重现这一点。

任何想法为什么会这样? 谢谢!

编辑1:

JobIntentServiceActivity拨打此Service不会崩溃。

编辑2:

firebase-core: 11.8.0

0 个答案:

没有答案