[FIXED] xamarin forms : Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable

Issue

When i run the application android OS 11 and below it is working but it not working Android os 12 when i deploy the application the following run time exception im getting.

[AndroidRuntime] Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
[AndroidRuntime]    at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
[AndroidRuntime]    at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:651)
[AndroidRuntime]    at android.app.PendingIntent.getBroadcast(PendingIntent.java:638)
[AndroidRuntime]    at com.google.firebase.iid.zzl.zzd(Unknown Source:18)
[AndroidRuntime]    at com.google.firebase.iid.zzl.zzb(Unknown Source:229)
[AndroidRuntime]    at com.google.firebase.iid.zzl.zza(Unknown Source:0)
[AndroidRuntime]    at com.google.firebase.iid.zzj.zzb(Unknown Source:41)
[AndroidRuntime]    at com.google.firebase.iid.zzj.getToken(Unknown Source:56)
[AndroidRuntime]    at com.google.firebase.iid.FirebaseInstanceId.getToken(Unknown Source:10)
[AndroidRuntime]    at com.google.firebase.iid.FirebaseInstanceId.zzcfy(Unknown Source:4)
[AndroidRuntime]    at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source:148)
[AndroidRuntime]    at com.google.firebase.iid.FirebaseInstanceIdService.handleIntent(Unknown Source:122)
[AndroidRuntime]    at com.google.firebase.iid.zzc.run(Unknown Source:4)
[AndroidRuntime]    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
[AndroidRuntime]    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
[AndroidRuntime]    at java.lang.Thread.run(Thread.java:1012)

Kindly help on this.

Solution

At first, you can debug to find which PendingIntent you used caused this error.

If it is created by yourself, you can try to set the flag as PendingIntentFlags.Immutable or the PendingIntentFlags.UpdateCurrent when you use the PendingIntent. For more information, you can check this case.

And if it is created by the nuget packages you used, you can try to upgrade the package’s version to the newest one.

In addition, the library mentioned in the case’s answer I provided above. It is the nuget package named Xamarin.AndroidX.Work.Runtime in the xamarin, you can install the last version in your project.

Answered By – Liyun Zhang – MSFT

Answer Checked By – Marilyn (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published