Resched. timer after cancel gives “java.lang.IllegalStateException: Timer cancelled.”

前端 未结 4 1779
走了就别回头了
走了就别回头了 2021-01-18 01:09

i would like to know whether i can schedule the timer again after i cancelled it. It was stated here, http://www.coderanch.com/t/452066/java/java/Exception-timer-IllegalStat

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 01:52

    Have you tried using a Runnable handler and setting it to regular intervals? Something like this:

    private Handler mUpdateHandler = new Handler();
    private Runnable mUpdateRunnable = new Runnable() {
        public void run() {
            mUpdateHandler.postDelayed(this, delay);
        }
    };
    mUpdateHandler.postDelayed(mUpdateRunnable, delay);
    

    where you specify the delay as you wish and you can do whatever you need to do in run().

提交回复
热议问题