You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JobIntentService重启后onCreate未被调用的问题排查求助

JobIntentService重启后onCreate未被调用的问题排查求助

大家好,我碰到了一个关于JobIntentService的棘手问题,想请各位帮忙分析下:

在Android 11(R)设备上,设备重启后我的JobIntentService的onCreate()方法能正常执行,服务也能正常工作;但如果我用kill -9命令强制杀死APK进程,或者修改代码后通过adb install重新安装应用,虽然能看到APK进程重新启动了,但onCreate()方法却从来不会被调用。

进程活跃后,我在日志里看到了这些GC相关的信息:

06-06 12:07:55.466 23558 23579 I m.test.svc: Waiting for a blocking GC ProfileSaver
06-06 12:07:55.478 23558 23579 I m.test.svc: WaitForGcToComplete blocked ProfileSaver on AddRemoveAppImageSpace for 12.485ms
06-06 12:07:55.494 23558 23572 I m.test.svc: WaitForGcToComplete blocked RunEmptyCheckpoint on ProfileSaver for 14.509ms
06-17 11:27:12.040 9550 9571 I m.test.svc: WaitForGcToComplete blocked ProfileSaver on ClassLinker for 11.334ms
06-17 11:27:12.054 9550 9564 I m.test.svc: WaitForGcToComplete blocked RunEmptyCheckpoint on ProfileSaver for 13.742ms

下面是我服务里的相关代码片段:

private fun createNotificationChannel(): String {
    val channelId = "my_service"
    val channelName = "My Background Service"
    val chan = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH)
    chan.lightColor = Color.BLUE
    chan.importance = NotificationManager.IMPORTANCE_NONE
    chan.lockscreenVisibility = Notification.VISIBILITY_PRIVATE
    val notificationMgr = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    notificationMgr.createNotificationChannel(chan)
    return channelId
}

private fun initiateForeground() {
    val channelId = createNotificationChannel()
    val notificationBuilder = NotificationCompat.Builder(this, channelId)
    val notification = notificationBuilder.setOngoing(true)
        .setSmallIcon(R.drawable.ic_launcher)
        .setPriority(NotificationManager.IMPORTANCE_HIGH)
        .setCategory(Notification.CATEGORY_SERVICE)
        .build()
    startForeground(101, notification)
}

override fun onCreate() {
    super.onCreate()
    initiateForeground()
}

希望各位能给我一些排查的方向或者可能的原因,非常感谢!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 09:17:59