开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜