I'm using the following code to show a longer than usual toast and it's working fine in displaying the wanted text for longer, with no difference in the perception of the user from an usual toast, except for the time.
Toast toast;
CountDownTimer mcd;
[...]
toast=Toast.makeText(getApplicationContext(),
StaticMethods.giveStringAccordingtoLanguage(action,language),
Toast.LENGTH_LONG);
mcd=new CountDownTimer(6000, 50)
{
public void onTick(long millisUntilFinished) {toast.show();}
public void onFinish() {toast.show();}
}.start();
But when the user exits the app if that custom toast is showing it keeps on showing until its time is finished.
I've tried to solve it with a code like this when the app is exiting:
try
{
toast.cancel();
}
catch (Exception e)
{
}
try
{
mcd.cancel();
}
catch (Exception e)
{
}
Anyway it doesn't work at all.
I've also tried to redefine the behavior of the ticks with a code like this:
mcd.onTick(long millisUntilFinished) {toast.cancel();}
mcd.onFinish() {toast.cancel();}
But that code isn't even correct, it looks that it only is correct if done in the creation of a new CountDownTimer object via new.
Any idea on how this could be solved? On worst case scenario I could just pop up a dialog which won't keep on showing after exiting the app, but I'd prefer to do it this way because I think it would be better for the user.