Questions tagged [android-toast]

A Toast is a momentary popup in Android which provides simple feedback about an operation.

Summary

A Toast is a momentary popup which provides simple feedback about an operation1. Toasts are added to an application's WindowManager and are not bound to an activity's UI; therefore, a Toast can remain visible after an Activity is navigated away from.

Toasts are typically displayed by using the makeText() method:

   // also supports Toast.LENGTH_LONG
Toast.makeText(getApplicationContext(), "some message", Toast.LENGTH_SHORT).show();

Sample Toast:-

enter image description here

It is important to note that the duration parameter requires either the LENGTH_LONG or LENGTH_SHORT . A custom millisecond value is not a valid duration parameter.

Custom Toasts

Toasts can use a custom View by using the setView() method3.

Usage

Toast messages should be as unobtrusive as possible4. Toasts should be used in situations that necessitate the user to be notified of certain background tasks such as a setting or draft being saved. Generally, Toasts should not exceed a single line of text.

Further reading

Toast overview

Toast developer guide

Toast code

Image Source and Brief guide

References:

1http://developer.android.com/guide/topics/ui/notifiers/toasts.html [Accessed on March 10, 2015]

2http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.2_r1/android/widget/Toast.java#Toast.0LENGTH_SHORT [Accessed on March 10, 2015]

3http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView [Accessed on March 10, 2015]

4http://developer.android.com/reference/android/widget/Toast.html [Accessed on March 10, 2015]

639 questions
10
votes
2 answers

Display two Toast messages at once?

I would like one Toast message to display in one location and a different Toast message to display in another location simultaneously. Multiple Toast messages seem to always queue and display in order. Is it possible to show both messages at the…
gotube
  • 671
  • 2
  • 5
  • 22
9
votes
1 answer

Toast.makeText() - activity or application context

I've read a couple of discussions on when to use activity and when to use application context (e.g. on this SO post). I'm wondering what the implications of using either activity or application context are for the method Toast.makeText(). The…
Peter F
  • 3,633
  • 3
  • 33
  • 45
9
votes
2 answers

Anko toast() method causes java.lang.NoSuchMethodError when called from Fragment

I'm having following error when I'm calling toast("Toast's message text") from Android Fragment: java.lang.NoSuchMethodError: No virtual method getActivity()Landroid/app/Activity; in class Landroid/support/v4/app/Fragment; or its super classes…
Jan Slominski
  • 2,968
  • 4
  • 35
  • 61
9
votes
3 answers

how to set text new line in Toast at center android

My Toast have 3 lines, I want line 2 and 3 show center of this toast and set duration to 10 seconds. How can do it? Like this picture:
Noisyman
  • 119
  • 1
  • 1
  • 7
9
votes
2 answers

Is it possible to disable Toasts or wait until toast disappears while testing

I am testing an app with Espresso. I have one question is it possible to wait until there are no toast are currently being showed. I have a lot of different toast in my app, but while testing I have problems with them because as far as I can guess…
CROSP
  • 4,499
  • 4
  • 38
  • 89
8
votes
9 answers

Android Toast Messages not working

I'm developing a game via Andengine for Android. I have MainActivity class and GameScene class. I use Toast messages in GameActivity. And it is working. Toast.makeText(this, " Hello World", Toast.LENGTH_SHORT).show(); So I wanna use Toast messages…
user3076301
  • 113
  • 1
  • 1
  • 6
7
votes
2 answers

how to show toast in WorkManager doWork()

how to show toast in WorkManager do work()? When I try, it throws Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Nurseyit Tursunkulov
  • 8,012
  • 12
  • 44
  • 78
7
votes
1 answer

Displaying Toast on Android AUTO DHU

I am building out a media player for Android Auto and struggling to make a simple Toast Message that appears on the Automotive Display Head Unit. In my Custom Actions, I have an action that needs to display a toast message on the Car interface, but…
erik
  • 4,946
  • 13
  • 70
  • 120
6
votes
1 answer

Unit test for Toast message content using Robolectric

I have an Activity that does nothing but showing a Toast message like the following. public MyActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
6
votes
0 answers

NotificationService: Toast already killed

When calling show toast message from AIDL service callback toast comes with flicker. I tried with runOnUiThread(), handler, etc... in AIDL callback but still it's not solving. Anyone faced similar issue?
Vishal Pawar
  • 4,324
  • 4
  • 28
  • 54
6
votes
1 answer

Display MessageBody of Firebase Notification as Toast

I am getting a run-time exception on displaying a Toast message java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() I want to display the message body as a Toast message when the user receives a push…
6
votes
4 answers

custom Toast at screen top

Please read the question before answering with your standard routine to print a Toast :) I'd like to display a Custom Toast at the top left corner of the screen. I use this code to create the Toast: Toast mFixedToast = new…
rupps
  • 9,712
  • 4
  • 55
  • 95
6
votes
4 answers

Android Toast message doesn't show

I know there are some other issues regard this problem, however, mine is surprisingly different (at least I think so). I guess my code is right but I don't have idea why toast message doesn't display. Firstly, I couldn't see toast message in my…
Hesam
  • 52,260
  • 74
  • 224
  • 365
5
votes
2 answers

Why do toasts get truncated when app is installed on Android 12 APi 31

The documentation says that Toasts are truncated to two lines on applications targeting Android 12 or later. The behaviour that I observe is that Toasts are truncated to two lines on applications installed on a device running Android 12 or…
Richard Parkins
  • 347
  • 2
  • 13
5
votes
0 answers

How to change default/place holder Blue Android Icon in Toast, Android 11

I'm testing my app on an Android 11 emulator (Pixel 5 API 31), when I open a toast notification I see the following: Where the toast has a blue default/place holder android icon next to it. How do I replace this placeholder icon with my own…
J34245
  • 300
  • 2
  • 12
1 2
3
42 43