In this article, we will cover mobile alerts in Xamarin.Forms. For any mobile app, it’s important to define with the user, client, or product owner if you will be working in an agile context (Scrum), and for Android or iOS. Even if we will work on a single shared project, we need to know what every environment can offer in native apps.

Toasts

It’s a simple plugin, Toasts.Forms.Plugin, that we can use in a Xamarin.Forms project. I advise starting with it because it’s similar to native Toast or notification APIs, especially for iOS developers. Notifications are placed in the center inline to be close to the native platform, with some changes in design, and it allows developer to perform sound and badges.

var options = new NotificationOptions()
{
Title = "Display notifications",
Description = "Some Description related to this title….",
IsClickable = false // Set to true if you need the result Clicked to come back (if the user clicks it)
};
// Use dependency service in order to resolve IToastNotificator.
var notification = DependencyService.Get<IToastNotificator>();
var result = await notification.Notify(options);

The result will return a NotificationResult with an Action having one of these values:

UserDialogs

I use the plugin Acr.UserDialogs by Allan Ritchie. It’s a new way to use popup link with some different design from Toast and Alert. As mentioned in the GitHub documentation, it allows the developer “to call for standards user dialogs from shared/portable library, Actionsheets, alerts, confirmations, loading, login, progress, prompt, toast.”

In this video, I explain how we can integrate the plugin Acr.UserDialogs.

The Simple Way: Native

In this article, the author explains how we can display a simple Toast in an Android environment using a component in native mode. The GitHub is here.