I’m updating a picture by using timer, but it causes fatal performance problem. Then I print logs and find out my timer runs faster rather than 1500.
So what’s the problem?
schedule at wrong rate:
startToDraw().353: System.currentTimeMillis() = 1332742387400
startToDraw().353: System.currentTimeMillis() = 1332742387410
startToDraw().353: System.currentTimeMillis() = 1332742387438
startToDraw().353: System.currentTimeMillis() = 1332742387449
startToDraw().353: System.currentTimeMillis() = 1332742387472
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
while (!isDestroyed) {
try {
Log.i(getClass().getName(), "startToDraw().353: System.currentTimeMillis() = " + System.currentTimeMillis());
handler.sendMessage(new Message());
} catch (Exception e) {
}
}
}
}, 0, 1500);
I think the problem is that you are entering a while loop that runs repeatedly. You probably just want to make a check if you are in an invalid state and then if you are, don’t perform the task. So I would change:
to: