FLAG_MUTABLE usage examples, when should I use it?

Viewed 105

Today I got this error in my app:

java.lang.IllegalArgumentException: com.money.saving: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. 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.

I don't understand when my PendingIntent is mutable.

In my application I use PendingIntent 2 times, the first time is to schedule an AlarmManager that repeats daily

AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarm.cancel(pendingIntent);
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, cHoraActivacion.getTimeInMillis(), (24 * 60 * 60 * 1000), pendingIntent);

The second to create a notification

AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, cFecha.getTimeInMillis(), pendingIntent);

I assume that when using setRepeating I should use FLAG_MUTABLE and in the case of notification I should use FLAG_IMMUTABLE, This assumption is because setRepeating has to undergo changes to see when it is activated. Am I correct?

0 Answers
Related