When we talk about "Toast" notification then, Mobile
Data Turned Off , Download Completed "comes to our mind.Yes, those small pop-ups are called Toast in Android.
Toast Notification is a Pop-up message that is shown on
the screen for a while and hides itself after a while. The example below demonstrates the usages of simple and customized toast in Android. In Android,Toast is a notification message that pop up, display a certain amount of time, and automatically fades in and out, most people just use it for debugging purpose. Toast is a solution for android developer when required to notify user about an operation without expecting any user input. This provides a small popup that displays for a small period and fades out automatically after timeout. Sometimes developers use this for debugging. For example, some of the app shows Press back once to Exit message when pressed back button in home page.Another real- time example is Gmail app, It shows a Toast, when a mail message is saved to draft How to Create a Toast We can instantiate a android.widget.Toast object using static makeText() method. This method takes three parameters: the application Context, the text message, and the duration for the toast. You can display the toast notification by calling show() method. Checkout below code snippet to show an simple toast in Android Toast Types 1. Normal Toast view. Toast Types 2. Custom Toast view. Toast notification Position Toast notification in android always appears near the bottom of the screen, centered horizontally as shown in the image. However, it allows us to change its position with the setGravity(int, int, int) method. This accepts three parameters: Gravity constant, x-position offset, y-position offset. For example, if you decide that the toast should appear in the top-left corner, you can set the gravity like this: AlertDialog Some times in your application , if you wanted to ask the user about taking a decision between yes or no in response of any particular action taken by the user, by remaining in the same activity and without changing the screen, you can use Alert Dialog. 1setIcon(Drawable icon) This method set the icon of the alert dialog box. 2setCancelable(boolean cancelable) This method sets the property that the dialog can be cancelled or not 3setMessage(CharSequence message) This method sets the message to be displayed in the alert dialog 4setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener) This method sets list of items to be displayed in the dialog as the content. The selected option will be notified by the listener 5setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) This method Sets the callback that will be called if the dialog is canceled. 6setTitle(CharSequence title) This method set the title to be appear in the dialog