Android:Toast消息消失后如何关闭应用程序?
正如标题所说。我试图在单击按钮时显示 Toast 文本,然后在消息消失后关闭应用程序。
Toast toast = Toast.makeText(getApplicationContext(), "Message here", Toast.LENGTH_SHORT);
toast.show();
finish();
这会在显示 toast 消息时关闭应用程序,我只是想知道是否可以将关闭应用程序延迟到消息消失后。
谢谢!
Just as the title says. I'm trying to have display a Toast text when a button is clicked, and then close the application after the message disappears.
Toast toast = Toast.makeText(getApplicationContext(), "Message here", Toast.LENGTH_SHORT);
toast.show();
finish();
This closes the application as the toast message displays and I was just wondering if I could delay closing the application to after the message disappears.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须设置一个计时器来计时吐司消失的时间。
如果我没记错的话,LENGTH_SHORT 是 2 秒或左右。
调用带有计时器任务的计时器,延迟 2 秒,依次调用 finish。
You will have to set a timer for the time it takes the toast to disappear.
If I'm not mistaken, LENGTH_SHORT is 2 seconds or around it.
Call a timer with a timer task with a 2 seconds delay that will call finish in turn.