持久化 Toast 消息:Toast 执行后不会消失 [英] Persistent Toast Message: Toast won't disappear after execution

查看:75
本文介绍了持久化 Toast 消息:Toast 执行后不会消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条执行后不会消失的 Toast 消息.我猜这与它在循环中有关,但我不确定.有人可以帮我弄清楚为什么 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);
}

}

推荐答案

如果您从服务线程调用 Toast 消息并且该线程在 Toast 设置为消失之前完成其工作,则该消息可能会卡住.然后你会被屏幕上的 Toast 消息卡住,直到你终止应用程序.

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.

这篇关于持久化 Toast 消息:Toast 执行后不会消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆