粘性前台服务无法重启“过程不好”。错误 [英] Sticky foreground service fails to restart with a "process is bad" error

查看:423
本文介绍了粘性前台服务无法重启“过程不好”。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已启动的前台服务。
我已经注意从onStartCommand返回START_STICKY。
我发现前台服务无法无限期运行,但会被一个名为 RestartProcessManager 的Android内部模块定期终止。本质上,一个进程LRU被维护,如果新配置的服务被配置为这样做(粘性或非粘性),则会再次调度它。
我面临的问题是如何处理重启。 Logcat表示服务意图正在传递,但由于进程不好而失败

I have a started foreground service. I've taken care to return START_STICKY from onStartCommand. I've observed that foreground services don't run indefinitely but are periodically terminated by an Android internal module called the RestartProcessManager. Essentially a process LRU is maintained and the newly terminated service gets scheduled again if it's configured to do so(sticky or not). The issue I'm facing is with how the restart is being handled. Logcat indicates the service intent was being delivered, but failed because the "process is bad"

在搜索其他来源后,我被认为是我的内存泄漏服务。为了验证这个声明,我创建了一个vanilla前台服务,除了在同一个应用程序中的 onStartCommand 期间记录语句外什么也没做。这也发现了同样的问题。

After scouring through other sources I was led to believe that there's a memory leak within my service. To validate this claim I created a vanilla foreground service that did nothing other than log a statement during onStartCommand within the same app. This too observed the same issue.

在一个新项目中尝试了完全相同的事情(显然有一个新的包名),服务重启完全正常。我也模拟了通过单击studio-> logcat下的红色十字按钮重启(这实际上会杀死进程)。无论如何,这次服务意图已成功交付,服务又重新启动并运行。
我认为它可能是我项目中的一些依赖项,可能会以某种方式搞乱。我在新项目中复制了依赖项,并继续按预期工作。

Tried the exact same thing in a new project (with a new package name obviously) and service restarts worked perfectly fine.Also, I simulate a restart by clicking the red cross button under studio->logcat (which essentially kills the process). Anyway, the service intent was successfully delivered this time and the service was up and running again. I assumed it could be some dependencies in my project that may be messing in some manner. I replicated the dependencies in the new project and it continued to work as expected.

现在这是荒谬的地方。我更改了错误项目中的包名称,我不再遇到问题了。我已经解决了这个问题,因为我花了将近2天的时间对此进行诊断,但由于我的应用程序已经发布,更改包名称对我来说是不可行的。

Now this is where it gets absurd. I change the package name in the buggy project and I don't encounter the issue anymore. I'd have settled for this as a fix because I spent close to 2 days diagnosing this, but changing the package name isn't feasible for me as my app is published already.

编辑-1:我必须提到我目前在我的设备上运行Oreo(一加5)

Edit-1: I must mention that I've observed this currently on my device running Oreo(one plus 5)

编辑-2:
该服务与应用程序在同一进程中运行。我也包括了logcat转储。

Edit-2: The service is running in the same process as the app. And I've included the logcat dump as well.

02-15 14:26:50.850  1395  1445 D RestartProcessManager: updateSelf :  com.ambee, size : 30
02-15 14:26:50.852  1395  1445 D RestartProcessManager: com.ambee got score 26.17240489145331 in DayDuration for duration : 525176
02-15 14:26:50.853  1395  1445 D RestartProcessManager: com.ambee got score 99.80218232889891 in DayLRU for LRU diff : 47707034
02-15 14:26:50.853  1395  1445 D RestartProcessManager: com.ambee got score 90.9090909090909 in DayLaunchTimes for launch times : 10
02-15 14:26:50.854  1395  1445 D RestartProcessManager: com.ambee : X : 2727.272727272727, Y : 785.1721467435993, Z : 2994.0654698669673
02-15 14:26:51.082  1395  1445 I ActivityManager: Killing 13839:com.ambee/u0a260 (adj 200): [BgDetect][RNK] kill com.ambee (uid 10260) usage 4
02-15 14:26:51.083  1395  1445 D ActivityManager: Process com.ambee has 1 services
02-15 14:26:51.083  1395  1445 W ActivityManager: Scheduling restart of crashed service com.ambee/.vson.LinkService in 10996ms
02-15 14:26:51.084  1395  1445 D EmbryoManager: prepare com.ambee user 0
02-15 14:26:51.099  3710  3710 D NotificationListener: onNotificationRemoved# hash: 68226270 sbn: StatusBarNotification(pkg=com.ambee user=UserHandle{0} id=903 tag=null key=0|com.ambee|903|null|10260: Notification(channel=default pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x72 color=0x00000000 actions=2 vis=PRIVATE))
02-15 14:26:54.121  1395  1444 I ActivityManager: Start proc 22570:com.ambee/u0a260 for embryo com.ambee
02-15 14:26:54.121  1395  1444 D Embryo_Uterus: Embryo created.com.ambee, pid=22570
02-15 14:26:54.796 22570 22570 D Embryo  : preload com.ambee, 10ms, hwui=true, layout=false, decor=false
02-15 14:27:02.084  1395  1445 W ActivityManager: Unable to launch app com.ambee/10260 for service Intent { cmp=com.ambee/.vson.LinkService }: process is bad
02-15 14:27:04.214  1395  1444 D Embryo_Uterus: rank:63, com.ambee, 35767806


推荐答案

提升KR_Android的评论:根据此博客另一个问题:声明服务意图在崩溃至少两次后坏。

Pushing up the comment of KR_Android : according to this blog and this other question : a service Intent is declared 'bad' after crashing at least twice.

请尝试


  • 封装中的所有方法try {method(..); } catch(..){log(..)} 安全带

  • 卸载并重新安装应用程序

  • Encapsulate all methods in try { method(..); } catch(..) { log(..) } security belts
  • Deinstall and reinstall the app

告诉我们,我们将在深入挖掘后更新我们的答案

Let us know and we shall update our answers after digging further

这篇关于粘性前台服务无法重启“过程不好”。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆