Our application has been receiving this new kind of crash since the beginning of the year.
Firebase shows it repeats only on Xiaomi with Android 11. It repeats in different parts of the application. And it seems unrelated to the application code. So I assume it is related to Xiaomi Android 11 update with broken code or new restrictions without clear explanation.
The obvious idea is pending intent creation spam, but I can't find any evidence that this method is frequently called, only several times.
Did anyone come out with a hack for that? Suppressing throwable is not a good option since the functionality won't work.
Code snippet:
val intent = Intent(context, SomeClass::class.java).apply {
this.action = action
this.putExtra(EXTRA_IDENTITY, identity)
}
PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
Stacktrace:
Fatal Exception: java.lang.SecurityException: Too many PendingIntent created for uid 10273, aborting Key{broadcastIntent pkg=<package> intent=act=<action name> cmp=<class> flags=0x0 u=0} requestCode=0
at android.os.Parcel.createExceptionOrNull(Parcel.java:2376)
at android.os.Parcel.createException(Parcel.java:2360)
at android.os.Parcel.readException(Parcel.java:2343)
at android.os.Parcel.readException(Parcel.java:2285)
at android.app.IActivityManager$Stub$Proxy.getIntentSenderWithFeature(IActivityManager.java:6898)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:578)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:561)
...
I'll answer the question since I haven't received any answer from SO, and our application has been getting this crash in different parts of the code without any noticeable connections.
So, you find this problem with such symptoms:
I would say it is caused by a bug or "restriction feature" on Xiaomi 11 update.
As a result, the best you can do is to wrap it with a try-catch.
P.s. if your crash looks different, you probably need to check other answers. Try catch is good, but ideally, you would like to fix the reason behind it.