I try to update a timer previsously set in my Android app.
Timer code :
timer.purge();
Data.Log.i("Next update : "+time * 60 * 1000);
timer.scheduleAtFixedRate(new TimerTask()
{
@Override
public void run()
{
handler.post(new Runnable() {
@Override
public void run() {
wp.StartUpdate();
}
});
}
}, 0, time * 60 * 1000);
So i cant update my timer. When i set it with “time = 2” every 2 minutes the timer execute even though I changed it to 60.
Where is the problem?
Once the timer is initialized, it stores the interval value of initialization time
time * 60 * 1000which is equal to 2 minutes iftime = 2. So this value is stored within timer object. Timer do not check this value at run-time, but uses its own locally stored value of interval which was supplied at initialization time.If you change the value of
time = xor any other, timer will not change its internal interval value. So if you want to change then interval value of timer later, You have to start another timer object with new interval value.