Short answer
If your app’s targetSdkVersion is 30 or lower, creating a PendingIntent without FLAG_IMMUTABLE or FLAG_MUTABLE results in a mutable intent (the system behaves as if FLAG_MUTABLE were supplied). When targetSdkVersion is 31 or higher, the same call throws an IllegalArgumentException ("Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified"), so there is no usable default — the intent is not created.
Confirmed facts vs. platform guidance
- API level 30 and lower: Omitting the mutability flag yields a mutable
PendingIntent. FLAG_IMMUTABLE exists since API 23 and can be used to lock extras. - API level 31+ with targetSdkVersion ≥31: The platform treats the missing flag as a hard error; the call fails before a
PendingIntent object is returned. - When
FLAG_IMMUTABLE is set: The receiving app cannot modify the intent’s extras via a fill‑in intent. - When
FLAG_MUTABLE is set: Other apps may modify the extras (required for features like notification inline replies).
Likely future behavior
There is no official statement that the default will become immutable in a later release. Because the platform already made the flag mandatory rather than changing a silent default, a future silent change is unlikely, but it is not guaranteed.
Recommended pattern
Always specify the mutability flag explicitly, defaulting to immutable unless a specific API requires mutability:
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags |= PendingIntent.FLAG_IMMUTABLE; // available from API 23
}
// Use FLAG_MUTABLE only where the framework contract demands it
PendingIntent pi = PendingIntent.getActivity(context, requestCode, intent, flags);
If your minSdkVersion is 23 or higher, you can omit the version check and always add FLAG_IMMUTABLE. Reserve FLAG_MUTABLE for documented cases (e.g., notification actions that need to fill in a remote‑input).
Verification
- Confirm
targetSdkVersion in build.gradle. - On an emulator or device with API 31+, try to create a
PendingIntent without flags and watch for IllegalArgumentException in logcat. - Audit your codebase:
grep -rn "PendingIntent\.get" --include="*.kt" --include="*.java" and verify each call includes a mutability flag.