Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

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() }
    }
}

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.

Thanks in advance.

like image 765
Dewey Reed Avatar asked Feb 16 '19 02:02

Dewey Reed


2 Answers

Huawei? For me it was reported only for Huawei devices in Firebase Crashlytics. So it could be a fail of this Manufacture. A really bad device https://dontkillmyapp.com/huawei

like image 145
user924 Avatar answered Nov 04 '22 09:11

user924


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);
}

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.

like image 24
zoulou Avatar answered Nov 04 '22 07:11

zoulou