Timer problem in android not outputting anything
I have the following code:
Timer micTimer = new Timer();
micTimer.schedule(new TimerTask(){
@Override
public void run(){
Log.v("Timer", "Timer");
}
}, 0, 1000);
Which in theory should every second output a log line Timer Timer, bu开发者_运维百科t does not. I understand its probably a better way to use a Handler and use the postDelay() method but this way if working seems adequate enough for my needs. I don't understand what is wrong with the code.
.
Try this:
class UpdateTimeTask extends TimerTask {
public void run() {
Log.v("Timer", "Timer");
}
}
--
Timer micTimer = new Timer();
micTimer.schedule(new UpdateTimeTask(), 0, 1000);
TimerTask is abstract, so you can't instantiate it directly - you need to extend it.
精彩评论