I want to have an operation(Task) to be Scheduled after some time OR Based on User Request.
In my code I have something like this
Timer timer = new Timer();
TimerTask timerTask = new TimerTask();
timer.schedule(timerTask,time);//Time in milli seconds
if(UserRequestedtoCancel)
{
// Do operatation
timerTask.cancel();
}
The problem is My task is still being executed after that time I specified, but only once.
Should I also do timer.cancel(), or something else to avoid the task been executed?
Thanks
setting the timerTask = null after calling timerTask.cancel(), worked for me. I Had the task executed only once either by the user or the scheduler !