Skip to content Skip to sidebar Skip to footer

Android: Toast Is Not Showing Before System.exit()

I have nested nested class where I am trying to display a toast for the outer most class before I exit the app. The toast works just fine if I comment out exit statement, so I know

Solution 1:

Thank you all who tried answering this for me, but unfortunately the solutions did not work.

Turns out that I have to do this when I try using Toast within a Service.

Once again, to those who tried answering it: thank you.

To those who down voted my post without stating the reason, next time leave constructive criticism rather than leaving me in the dark. I'm here to learn and I can't learn if you simply down vote with providing a legit reason. I'm not a mind reader.

Solution 2:

USE getApplicationConext() INSTEAD OF CONTEXT

Toast.makeText(getApplicationConext(), "Timer up. Existing app...", Toast.LENGTH_SHORT).show();

Solution 3:

Handler disToast= newHandler(newCallback() {
   @OverridepublicvoidhandleMessage(Message msg) { 
             String mString=(String)msg.obj;
             Toast.makeText(this, mString, Toast.LENGTH_SHORT).show();
          }
});

 privateRunnable r = newRunnable() {


    publicvoidrun() {


        newCountDownTimer(3000, 1000) {

            publicvoidonFinish() {



            Message msg=disToast.obtainMessage();
            msg.obj="your message";
            disToast.sendMessage(msg);

                handler.removeCallbacks(updateTimerThread);
                System.exit(0);
            }
        }.start();

};

More details Refer Here

Solution 4:

please use

Toast.LENGTH_LONG instead of

Toast.LENGTH_SHORT


 Toast.makeText(context, "Timer up. Existing app...", Toast.LENGTH_LONG).show();

Now your toast will be display after System.exit();

Post a Comment for "Android: Toast Is Not Showing Before System.exit()"