Android RemoteServiceException:startForeground:java.util.ConcurrentModificationException的错误通知

Android RemoteServiceException:startForeground:java.util.ConcurrentModificationException的错误通知,android,android-service,Android,Android Service,我收到这起车祸报告已经有一段时间了。这似乎只发生在Android 8.0.0上 android.app.RemoteServiceException: Bad notification for startForeground: java.util.ConcurrentModificationException at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2204) at android.os.Hand

我收到这起车祸报告已经有一段时间了。这似乎只发生在Android 8.0.0上

android.app.RemoteServiceException: Bad notification for startForeground: java.util.ConcurrentModificationException
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2204)
  at android.os.Handler.dispatchMessage(Handler.java:108)
  at android.os.Looper.loop(Looper.java:166)
  at android.app.ActivityThread.main(ActivityThread.java:7523)
  at java.lang.reflect.Method.invoke(Method.java:-2)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
每个频道都已设置好,该应用程序可以在Android 8.0.0及更高版本的设备上运行,在测试过程中没有任何问题,除非我无法重现崩溃

我想知道为什么会发生这种崩溃,以及如何修复它


提前感谢。

我也会在安卓8.0.0设备上随机遇到这个崩溃

查看AOSP源代码,它似乎是由以下行生成的:

不确定这个catch块上面的try块中到底是哪一行导致了它,但我假设AOSP本身有一个bug。它与通知异步操作。
因此,当AOSP也在应用程序上运行时,应用程序更新其通知的可能性相当高。

我的应用程序有时会更改前台通知。在我使用下面的代码之后,我已经有一段时间没有看到崩溃了。但我不确定它是否能解决所有问题

public void postNotification() {
...
} catch (RuntimeException e) {
    Slog.w(TAG, "Error showing notification for service", e);
    // If it gave us a garbage notification, it doesn't
    // get to be foreground.
    ams.setServiceForeground(name, ServiceRecord.this,
            0, null, 0);
    ams.crashApplication(appUid, appPid, localPackageName, -1,
            "Bad notification for startForeground: " + e);
}

华为?对我来说,只有Firebase Crashlytics中的华为设备报告了这一点。所以这可能是这个制造的失败。非常糟糕的设备

您能显示stacktrace和/或代码部分吗?我想您可以使用collection来处理一堆通知消息,对吗?@Raskilas我添加了stacktrace和代码。你说得对,我处理一堆通知,并把其中一个放在前台。但我仍然不知道它为什么会触发ConcurrentModificationException。你找到解决方案了吗?@yoonhok没有。但我决定暂时忽略这次崩溃,因为越来越多的用户正在使用Android P或Q。@Dewey Reed,那太糟糕了。。那你知道原因吗?还是复制场景?你找到解决方案了吗?对我来说,这通常发生在使用华为设备的用户身上(根据Firebase Crashlytics的报告)
public void postNotification() {
...
} catch (RuntimeException e) {
    Slog.w(TAG, "Error showing notification for service", e);
    // If it gave us a garbage notification, it doesn't
    // get to be foreground.
    ams.setServiceForeground(name, ServiceRecord.this,
            0, null, 0);
    ams.crashApplication(appUid, appPid, localPackageName, -1,
            "Bad notification for startForeground: " + e);
}
private val toForegroundHandler: Handler = Handler(Looper.getMainLooper())

@Synchronized
override fun toForeground(id: Int) {
    toForegroundHandler.removeCallbacksAndMessages(null)
    toForegroundHandler.postDelayed(16) {
        startForeground(id, builder.build())
    }
}