RemoteServiceException:startForeground的错误通知:java.util.ConcurrentModificationException [英] RemoteServiceException: Bad notification for startForeground: java.util.ConcurrentModificationException
问题描述
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上.
I've been receiving this crash report for quite some time. It seems that this only happens on Android 8.0.0.
@Synchronized
override fun toForeground(id: Int) {
fun action() {
startForeground(id, builder?.build())
}
if (Looper.myLooper() === Looper.getMainLooper()) {
action()
} else {
Handler(Looper.getMainLooper()).post { action() }
}
}
每个频道均已设置,并且该应用程序可以在Android 8.0.0和更高版本的设备上运行,并且在测试过程中没有任何问题,除非我无法重现崩溃.
Every channel has set up and the app can be run on Android 8.0.0 and later devices without any problem during testing except I cannot reproduce the crash.
我想知道为什么会发生此崩溃以及如何解决它.
I'm wondering why this crash happens and how to fix it.
谢谢.
推荐答案
我也在Android 8.0.0设备上随机遇到此崩溃.
I also face this crash on Android 8.0.0 devices randomly.
Looking into AOSP source code it seems to result from this line: http://androidxref.com/8.0.0_r4/xref/frameworks/base/services/core/java/com/android/server/am/ServiceRecord.java#540:
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);
}
不确定该catch块上方try块中的确切行会导致它,但是我假设AOSP本身存在错误.它与通知异步运行. 因此,在AOSP也在其上运行的同时,应用程序更新其通知的机会非常高.
Not sure what line exactly in the try block above this catch block causes it, but I assume a bug in AOSP itself. It operates with the notification asynchronously. So the chance that the app updates its notification while AOSP also operates on it, is quite high.
这篇关于RemoteServiceException:startForeground的错误通知:java.util.ConcurrentModificationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!