【发布时间】:2019-09-17 13:30:51
【问题描述】:
首先, 我看了这些;
- Context.startForegroundService() did not then call Service.startForeground()
- Context.startForegroundService() did not then call Service.startForeground
- Android 9 (Pie) Only: Context.startForegroundService() did not then call Service.startForeground() - Works fine on Oreo
- RemoteServiceException Context.startForegroundService() did not then call Service.startForeground()
- https://issuetracker.google.com/issues/76112072
我有一个将近一百万人使用的流媒体应用程序。我正在为播放器使用前台服务。我还没有实现MediaSession。我有 99.95% 的无崩溃会话。
所以这个应用程序适用于所有版本,但我开始收到 android 9 的崩溃报告 (ANR)。这种崩溃只发生在Samsung 手机,尤其是s9, s9+, s10, s10+, note9 型号。
我试过这些,
- 在
onCreate()中调用startForeground()方法 - 在
Context.stopService()之前调用Service.startForeground() - 类似问题的其他 stackoverflow 答案
我从 Google 的开发人员那里读到了一些 cmets,他们说只是 Intended Behavior。我想知道它是由三星的系统还是 Android 操作系统发生的。有人对此有意见吗?我该如何解决这个问题?
【问题讨论】:
-
是否有不能调用 startForeground 的路径?还是主线程停滞/休眠/做太多工作无法处理服务启动的路径?
-
这是一个广播/音乐应用程序,它只是播放流 URL。我的手机没有崩溃。有用户表示在后台听音乐时发生崩溃
-
如果编写完美的应用程序有可能发生这种情况,我不会感到惊讶,因为无法保证您的代码会及时被调用。虽然this answer 中的特定代码部分是一团糟,但解决方法似乎有希望:通过绑定让服务运行,将其移动到前台,然后使用
startForegroundService(),然后取消绑定稍后。 -
对。通过 startForegroundService 启动前台服务以调用 startForeground I 服务后,您有一个短窗口。出于某种原因,这在这些设备上发生得不够快
-
如果这仅本地化到三星设备,则表明他们的自定义版本的 Android 9 AOSP 存在错误 - 而不是您的代码。在可以忠实再现之前,任何解决方法都只是猜测。
标签: android android-service foreground-service