Multiple CountDown Timer running one after another

£可爱£侵袭症+ 提交于 2019-12-06 13:14:52

You probably need to break out the start timer functionallity and call it in onFinish().

    public void startTimer(int counterId){
            Counter counter = null;
            switch(counterId){
                    case 0:
                            counter = new CounterOne(counterId,user_input1,1000);
                            break;  
                    /* Counter 1-5  goes here*/
                    default:
                            break;
            }
            if(counter !=null ){
                    counter.start();
            }
    }

then start your next timer in onFinsh()

    public abstract class Counter extends CountDownTimer
    {
            private int counterId;

            public Counter(int counterId /*counter id start with 0*/,long millisInFuture, long countDownInterval)
            {
                    super(millisInFuture, countDownInterval);
                    this.counterId = counterId;
            }

            public abstract void onTick(long millisUntilFinished);

            public void onFinish()
            {
                    playSound(sound_id_1);
                    runMyMethod(user_input_1);
                    startTimer(this.counterId++);
            }

    }

    public class CounterOne extends Counter{
            public void onTick(long millisUntilFinished)
            {
                    //counter 1 logic
            }
    }

    /* Subclass others. eg. CounterTwo etc. */

You never set

timerHasStarted

to true. It's always false, so...yeah, one timer after another. Set it to true before calling counter.start() and it should work.

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