How to resolve "Missing PendingIntent mutability flag" lint warning in android api 30+?


As soon as I updated the target SDK to 30+ (Android R or later), a lint warning Missing PendingIntent mutability flag appeared on my PendingIntent.FLAG_UPDATE_CURRENT flag when I want to define PendingIntent.

How should I handle this lint with no effect on the app functionality?


You can set your pending intent as

val updatedPendingIntent = PendingIntent.getActivity(
   PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT // setting the mutability flag 

According to the docs here:

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.

Choose your flag accordingly.

If you want to read more about this i would suggest that you read this great article here:

Answered By – Mayur Gajra

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published