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
相关产品推荐
相关产品推荐

