Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
778 views
in Technique[技术] by (71.8m points)

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), 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?

question from:https://stackoverflow.com/questions/67045607/how-to-resolve-missing-pendingintent-mutability-flag-lint-warning-in-android-a

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can set your pending intent as

val updatedPendingIntent = PendingIntent.getActivity(
   applicationContext,
   NOTIFICATION_REQUEST_CODE,
   updatedIntent,
   PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT // setting the mutability flag 
)

According to the docs here: https://developer.android.com/about/versions/12/behavior-changes-12#pending-intent-mutability

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: https://medium.com/androiddevelopers/all-about-pendingintents-748c8eb8619


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...