Toast messages in Android Programming are similar but they are terminated/dismissed by itself (we do not have any buttons). We need to set a time period for which the message has to be displayed, when the time is reached the message fades away, it is usually shown at the bottom of the Activity page.
Some examples where you can an Android Toast Message be helpful.
Example 1 : We have an Email application and user deletes a email, then when that email is been deleted we can display a Toast message saying "Email has been deleted"
Example 2 : At login if the email-id or password is incorrect we can display a toast message saying "Invalid id or password"
Example 3 : When a message has been sent, we can notify the user "Message sent" using toast messages.
Lets see how Toasts works :
The above code snippet is the structure of creating a Toast object and setting a "Text" message and its "Duration"
makeText() is the method we have to use which takes in three parameters, Lets see each of these parameters one-by-one,
1. Context :
It is the Application context.
You can get the Application context using,
Another way of getting Context is referring to Activity class that you are displaying the Toast message.
If suppose the Activity class is MainActivity where we want to display the message,
You can also refer to the class by simply referring "this"
2. Text :
It is the string message that you want the toast to display on the Android Activity screen.
Posts related to android.
1. Share image and text Twitter using your Android Application Programatically
2. The Android Virtual Device 'myEmulator' is currently running an emulator and cannot be deleted.
3. Make Android View Scrollable both Horizontally and Vertically
4. Can we move apps like WhatsApp, Facebook to external MicroSD card
5. Parsing Data for android-21 failed unsupported major.minor version 51.0
6. Android : Prevent App for rotation landscape or portrait
7. ADT quit unexpectedly error on Mac OSX Android Eclipse SDK
8. Android-Failed to install apk on device EOF Timeout Error
9. How to change Android EditText Cursor Color
10. JavaDocs for Android SDK Eclipse IDE
11. Two Buttons next to each other in Android Layout
12. Change Title text for Android Activity using java code
13. How to add Newline to text in Android TextView
14. Android : Unable to load VM from snapshot : Mac OS X Error
15. INVALID FILE NAME: MUST CONTAIN ONLY [a-z0-9_.] Android Eclipse Error
16. Hide Tittle bar and Navigation bar from android activity
17. appcompat_v7 errors after updates to API level 21 Material Theme
18. How to Copy Text to Android Clipboard Programatically ClipboardManager (Both Old and New SDK)
19. [Solution] Running Android Lint has encountered a problem NullPointerException Error
20. Remove Trailing zeros BigDecimal Java