I created a TimerTask with the following code:
Screen_Timer_Task = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable()
{
@Override
public void run()
{
// Do my stuff
}
});
}
};
Then, I start that TimerTask with that:
Screen_Timer.scheduleAtFixedRate(Screen_Timer_Task, 1, 1);
This is working fine. But after calling
Screen_Timer.cancel();
Screen_Timer.purge();
it will not restart with
Screen_Timer.scheduleAtFixedRate(Screen_Timer_Task, 1, 1);
The app is just crashing!!
"The task may be run once " from docs timerTask
You must create TimerTask object again if you want to use it.
Also make Timer once again because cancel():
"Cancels the Timer and all scheduled tasks. If there is a currently running task it is not affected. No more tasks may be scheduled on this Timer. Subsequent calls do nothing."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With