I have a quit() method that I am using. I use a toast to print out "thank you for using this app". On the next line I do a system.exit(0); and when I run the app, the toast doesn't show before the system exits the app. Is there a way to fix this?

有帮助吗?

解决方案

The way you should do it, in your activity:

Toast.makeText(this,"Thanks for using the app",Toast.LENGTH_SHORT).show();
finish();

Forget System.exit

其他提示

You could run a thread that waits for the duration of your Toast.-

Thread thread = new Thread(){
    @Override
    public void run() {
        try {
            Thread.sleep(WAIT_TIME_IN_MILLIS);
        } catch (Exception e) {
            e.printStackTrace();
        }  
    }
};

thread.start();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top