Android Timer is called twice

泄露秘密 提交于 2019-12-12 01:56:15

问题


Hey guys

I'm trying to develop a little slide show in android. I've implemented the timer with a timertask and as expected the "run"-method is called everytime after the delay. But, however, when the delaytime has passed, the run method is called twice, so that the slide show slides two pictures instead of one.

Can anyone help me to solve this problem? Heres some code for better understandig what i've done.

public void startTimer() {
    if(timer == null) {
        timer = new Timer();
    }

    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            timerHandler.post(new Runnable() {

                @Override
                public void run() {
                    Log.d("Hier herein", "Timer abgelaufen");

                }   
            }); 
        }
    }, 7000, 7000); 
}

The startTimer()-Method is only called once, so I really don't understand, why the function is called twice. Thanks in advance :D

来源:https://stackoverflow.com/questions/16769341/android-timer-is-called-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!