In Android, an application can push a message to user called Notification outside its normal UI.
First, the notification will appear on the Notification Bar
User can see all the detail of a notification by opening the Notification Drawer
Android Notification has 2 views: Normal View and Big View. In this post, I only focus on Normal View. Big View will have its own entry later :)
To push a notification, first of all, you need to create a NotificationManager object:
Then, create a Notification object:
The constructor of Notification has 3 arguments:
After that, create a PendingIntent instance by calling PendingIntent.getActivity() method. This instance will start an activity when user tap on the notification.
Assign the latest notification by setLatestEventInfo() method:
Push the notification:
The notify() method has 2 arguments:
The result of this demo application: