Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 试图让倒计时在15秒后重新启动。_Android_Restart_Countdowntimer - Fatal编程技术网

Android 试图让倒计时在15秒后重新启动。

Android 试图让倒计时在15秒后重新启动。,android,restart,countdowntimer,Android,Restart,Countdowntimer,我正在做一个应用程序,显示各种瑜伽姿势60秒。我一直在拼命想让倒计时器按我想要的方式工作。我需要定时器能够暂停,并在15秒后自动重启。安卓系统的倒计时没有工作,因为它没有暂停。我尝试了两个不同版本的重写Android CountDownTimer和经典版本(Android CountDownTimer),它们似乎都有相同的错误,因为它们使用的是处理程序 我试过这个版本: 我尝试过这个版本:-我添加了一个onFinish方法 我尝试在onFinish方法中执行Thread.sleep 15秒,但在

我正在做一个应用程序,显示各种瑜伽姿势60秒。我一直在拼命想让倒计时器按我想要的方式工作。我需要定时器能够暂停,并在15秒后自动重启。安卓系统的倒计时没有工作,因为它没有暂停。我尝试了两个不同版本的重写Android CountDownTimer和经典版本(Android CountDownTimer),它们似乎都有相同的错误,因为它们使用的是处理程序

我试过这个版本:

我尝试过这个版本:-我添加了一个onFinish方法

我尝试在onFinish方法中执行Thread.sleep 15秒,但在进入Thread.sleep模式之前,它不会在最后一秒更新UI。在下面的代码中,直到Thread.sleep调用之后,TextView才会更新为空字符串

cdt = new CountDownTimerWithPause(60000,1000,true) { 
        @Override
        public void onTick(long millisUntiFinished) { 
            tvClock.setText("Remaining:" + millisUntiFinished/1000);

        }

        @Override
        public void onFinish() {
            tvClock.setText("");
            bell.start();
            if (bAutoPlayIsOn) { 

                tvClock.setText("waiting for next pose...");
                try {

                    //15 second pauses between poses
                    Thread.sleep(15000);
                    //start over
                    listener.onForwardItemSelected();
                    ResetClocktoMaxTime(60000);
                    resume();
                } catch (InterruptedException e) {
                    Log.d("Sleep Interrupted", e.toString());
                    e.printStackTrace();
                }
                catch (Exception e) {
                    Log.d("Timer", e.toString());
                }
            }
            else { 
              tvClock.setText("Done");
                       btnStart.setText("Start ");
              bClockIsTicking = false;
              btnStart.setCompoundDrawablesWithIntrinsicBounds(null, playBtn, null, null);
            }

        }
    };

有人知道如何以不同的方式执行此操作(15秒后重新启动)吗?

正在从接口线程调用onFinish方法,因此在onFinish返回之前,您所做的任何接口更改实际上都不会重新绘制。试着这样做:

  cdt = new CountDownTimerWithPause(60000,1000,true) {
      @Override
      public void onTick(long millisUntiFinished) {
          tvClock.setText("Remaining:" + millisUntiFinished/1000);

      }

      @Override
      public void onFinish() {
          tvClock.setText("");
          bell.start();
          if (bAutoPlayIsOn) {

              tvClock.setText("waiting for next pose...");
              (
                new Thread() {
                    public void run() {
                        try {
                            //15 second pauses between poses
                            Thread.sleep(15000);
                            getActivity().runOnUiThread
                            (
                              new Runnable() {
                                  public void run() {
                                    //start over
                                    listener.onForwardItemSelected();
                                    ResetClocktoMaxTime(60000);
                                    resume();
                                  }
                              }
                            );
                        }
                        catch (InterruptedException e) {
                            Log.d("Sleep Interrupted", e.toString());
                            e.printStackTrace();
                        }
                        catch (Exception e) {
                            Log.d("Timer", e.toString());
                        }
                    }
                }

              ).start();

          }
          else {
            tvClock.setText("Done");
            btnStart.setText("Start ");
            bClockIsTicking = false;
            btnStart.setCompoundDrawablesWithIntrinsicBounds(null, playBtn, null, null);
          }

      }
  };   

哈,我把群众难倒了(