PendingIntent is a powerful feature in the Android SDK that allows an application to pass a runnable piece of data (an Intent) to another application (usually a system service) to be executed at a later time. It essentially acts as a wrapper around an Intent so that it can be fired by another application even if your application context is no longer available.
PendingIntents are commonly used for notifications, alarm services, and broadcast receivers. For example, when a user interacts with a notification, the PendingIntent allows your app to resume or perform a task without being open at that moment.
// Create an Intent to launch your activity
Intent intent = new Intent(context, YourActivity.class);
// Create a PendingIntent to wrap the Intent
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Use the PendingIntent in a notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Title")
.setContentText("Content text")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent) // Set the PendingIntent that will be triggered
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(NOTIFICATION_ID, builder.build());
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?