How can I make a toast after stopping the timer?
onCreate {
//other code
myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
TimerMethod();
}
}, 0, 1000);
Toast.makeText(getApplicationContext(), "AS", 455).show();
}
private void TimerMethod()
{
this.runOnUiThread(Timer_Tick);
}
private Runnable Timer_Tick = new Runnable() {
public void run() {
rub_stat++;
if (rub_stat == 15){myTimer.cancel(); } }
};
So after rub_stat reaches 15 I want to cancel the timer and make the toast appear. Thanks in advance!
You may want to make a separate thread, not on the UI thread, so basically replace
with a thread call, and then you can join the thread, and have that thread pause for 15 seconds, and immediately after the join then show the
Toast.showToastwould just be a function to show the toast.I haven’t tested this code out, but it should be close to what you need.
For more on
joinyou can look at this blog article:http://cnapagoda.blogspot.ca/2010/01/thread-join-method.html