In Android development, a PendingIntent is a reference to a token that you give to another application (e.g., NotificationManager, AlarmManager, etc.) which allows the recipient to execute a predefined piece of code as if it were executed from your application. However, when you want to make your PendingIntent backward compatible, especially for devices running older versions of Android, it's important to use the right methods and flags.
Here’s an example of how to create a PendingIntent that will work on both newer and older Android versions:
Intent intent = new Intent(this, TargetActivity.class);
PendingIntent pendingIntent;
// For Android O and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
// For older versions
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?