Android uses notifications (Notification)

Notification is a feature in the Android system. Let's take a look at how Notification is used.
First, a NotificationManager is needed to manage notifications, which can be obtained through the getSystemService() method of Context. Here you need to pass in Context.NOTIFICATION_SERVICE to get NotificationManager. Next, you need to create a Notification object, which is used to store various information about the notification. The previous version of Andorid was constructed directly, that is, Notification notification = new Notification(); Now this is generally not done, and the Notification.Builder object is used to create the Notification.
First look at the usage of basic notification

public class NotificationActivity extends AppCompatActivity {
    Button btn_notification;

    protected void onCreate(Bundle savedInstanceState) {
        btn_notification = (Button) findViewById(;
        final NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        Notification.Builder builder = new Notification.Builder(this);
        final Notification mNotification =;
        btn_notification.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {


    public PendingIntent getDefault(int flag) {
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, new Intent(), flag);
        return pendingIntent;

The difference between Intent and pendingIntent
pendingIntent can be used to start an activity, start a service or send a broadcast. This is very similar to an Intent. A pendingIntent can be understood as a delayed-execution Intent. The way to get a PendingIntent is very simple, you can choose getActivity() or getService() or getBroadcast()

Summary: The basic usage of notification is very simple. If you want to add click events or carry parameters, you can do it in the third parameter Intent of PendingIntent.

Guess you like