The notification builder
Some tasks take a long time, or events may occur when the user is not using our app. Because some tasks take a long time, we run them in the background. As a result, we need to let the user know when a task is complete, or that some extra information is needed.
Getting ready
If we are going to support Android versions prior to 3.0, we will have to install the Xamarin Support Library v4 NuGet or component into our project.
How to do it...
If an event occurs when the user is not using our app, we can let the user know about it by using a Notification
instance from the following steps:
Create the notification using the
NotificationCompat.Builder
instance:var builder = new NotificationCompat.Builder(this) .SetSmallIcon(Android.Resource.Drawable.StatNotifySync) .SetContentTitle("Simple Notification") .SetContentText("Hello World!") .SetAutoCancel(true);
Or, if only supporting Android versions 3.0 and above, use the
Notification.Builder
instance:var builder = new Notification...