Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent Toast Message: Toast won't disappear after execution

Tags:

android

toast

I have a toast message that doesn't disappear after execution. Im guessing it has something to do with it being in the loop but I'm not sure. Can someone help me figure out what why the toast message doesn't disparate?

 @Override
public void onClick(View v) {
    int index = 0;
    for(int i= 0; i<userArray.length; i++){
        if(email.getText().toString().equals(userArray[i])){
            index = i;
        }
        if(passArray[index].equals(password.getText().toString())){
            Toast.makeText(getBaseContext(), "SUCCESS!", Toast.LENGTH_SHORT).show();

        } else {
            Toast.makeText(getBaseContext(), "INVALID LOGIN", Toast.LENGTH_SHORT).show();
        }
    }
    Intent mainIntent = new Intent(LoginActivity.this, MainActivity.class);
    startActivityForResult(mainIntent, 0);
}

}

like image 804
pzyren Avatar asked Mar 21 '13 05:03

pzyren


People also ask

How long does toast notification last?

Toast notifications are used to communicate low severity level information to users in an unobtrusive way. This notification will disappear after 8 seconds if not dismissed via the close button.

How do you dismiss a toast?

The toast can be dismissed automatically after a specific amount of time by passing the number of milliseconds to display it in the duration of the toast options. If a button with a role of "cancel" is added, then that button will dismiss the toast.

How long should a toast message display?

A toast message displays briefly, never receives focus, and disappears without user interaction. The default amount of time a toast message displays is 2 seconds, or if longDisplay is set to true, it displays for 3.5 seconds. The default length may vary depending on the version of the Android OS.


1 Answers

A Toast message can become stuck if you call it from a Service thread and that thread completes it's work before Toast is set to disappear. You are then stuck with the Toast message on the screen until you kill the app.

like image 96
Jonathan Cole Avatar answered Sep 30 '22 04:09

Jonathan Cole