Android:完成应用程序/活动后显示吐司
我想在退出应用程序时显示一个简单的吐司。问题是,吐司没有显示。我认为这是因为活动已完成或因为 System.exit(0)
,但我不知道如何解决它。有人有提示吗?谢谢!!
在我的活动中,我有以下代码:
Toast.makeText(this,"Exit application.",Toast.LENGTH_SHORT).show();
exitApp();
public void exitApp (){
App.getInstance().exit();
finish();
}
并且该方法在应用程序中退出:
public void exit() {
System.exit(0);
}
I want to show a simple toast, when exiting an application. The problem is, that the toast is not shown. I assume it is because the acitivity is finished or because of System.exit(0)
, but I don't know how to solve it. Does anyone have a tip? Thanks!!
In my activity I have the following code:
Toast.makeText(this,"Exit application.",Toast.LENGTH_SHORT).show();
exitApp();
public void exitApp (){
App.getInstance().exit();
finish();
}
And the mehod exit in App:
public void exit() {
System.exit(0);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
建议您调用 finish 来关闭应用程序,而不是调用
System.exit(0);
,因为这种方法会完全终止您的应用程序。System.exit() 杀死你的整个进程。
finish()
只是隐藏、停止并销毁您的活动。您的进程仍在运行。您只需使用
finish();
关闭您的活动,这应该可以解决您的问题。http://groups.google.com/group/ android-developers/browse_thread/thread/63de8a9cdffa46a3?pli=1
It is advisable that you call finish to close your application rather than calling
System.exit(0);
since this approach will kill your application completely.System.exit()
kills your entire process.finish()
just hides, stops and destroys your activity. Your process is still running.You can just use
finish();
to close your activity and this should solve your problem.http://groups.google.com/group/android-developers/browse_thread/thread/63de8a9cdffa46a3?pli=1
我刚刚启动了一个新线程,以便在系统进程被终止之前让 Toast 有时间显示。一探究竟:
I just fired off a new thread to allow time for the Toast to show before the system process is killed. Check it out: