Set Android Toast to a very long duration (e.g. 1 minute)

I am trying to set the duration of a Toast show as 1minute. I try this:

  final Toast toast = Toast.makeText(getApplicationContext(), "MESSAGE", Toast.LENGTH_LONG );
  toast.show();

    Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
               @Override
               public void run() {
                   toast.cancel(); 
                   }
            }, 60000);

Thank you for your help.

+4
source share
6 answers

Since LENGTH_SHORT is 2 seconds (and LENGTH_LONG is 3.5 seconds), try the following:

for (int i=0; i < 30; i++)
{
    Toast.makeText(this, "MESSAGE", Toast.LENGTH_SHORT).show();
}
+7
source

There are only two possible durations Toast: short (2 seconds) and long (3.5 seconds).

If you need a more permanent message, use the dialog box or specify a message in your layout.

- Crouton.

+4

.

LENGTH_SHORT LENGTH_LONG 0 1. , , , , - , .

+3
final Toast tag = Toast.makeText(getBaseContext(), "YOUR MESSAGE",Toast.LENGTH_SHORT);

tag.show();

new CountDownTimer(9000, 1000) {

    public void onTick(long millisUntilFinished) {tag.show();}
    public void onFinish() {tag.show();}

}.start();

. .

+1

Toasts are not intended to be used in this way. Toasts are transitory, and Android has defined them as SHORT and LONG.

If you want, you can create a dialog box than completely emulate the appearance of the Toast, but I would use a debugging dialog or notification, as this may disappoint the user to show the toast for a whole minute without the ability to reject it.

0
source

All Articles