Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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 Studio JUnit测试_Android_Junit_Android Animation_Runnable - Fatal编程技术网

可运行和动画停止Android Studio JUnit测试

可运行和动画停止Android Studio JUnit测试,android,junit,android-animation,runnable,Android,Junit,Android Animation,Runnable,我有多个JUnit测试,它们单击触发这些函数的按钮: public void startTimer() { startTime = SystemClock.uptimeMillis(); handler.post(runTimer); blink(); } Runnable runTimer = new Runnable() { @Override public void run () { millisecondTime = SystemCl

我有多个JUnit测试,它们单击触发这些函数的按钮:

public void startTimer() {
    startTime = SystemClock.uptimeMillis();
    handler.post(runTimer);
    blink();
}

Runnable runTimer = new Runnable() {
   @Override
   public void run () {

       millisecondTime = SystemClock.uptimeMillis() - startTime;
       updateTime = bufTime + millisecondTime;
       Seconds = (int) (updateTime / 1000);
       Minutes = (int) (updateTime / 60000);
       Hours = Minutes / 60;
       Minutes = Minutes % 60;
       Seconds = Seconds % 60;
       MilliSeconds = (int) (updateTime % 1000);
       timer.setText(String.format("%02d", Hours) + ":" + String.format("%02d", Minutes) + ":"
                        + String.format("%02d", Seconds));

       handler.postDelayed(this, 0);
}

public void blink() {
     Animation anim = new AlphaAnimation(0.0f, 1.0f);
     anim.setDuration(250); //You can manage the blinking time with this parameter
     anim.setStartOffset(0);
     anim.setRepeatMode(Animation.REVERSE);
     anim.setRepeatCount(Animation.INFINITE);    
     redCircle.startAnimation(anim);
}
对于上下文,JUnit测试的下一步单击调用停止动画和handler.removeCallbacks(runTimer)的按钮。然而,它甚至没有到达那里,因为它只是卡住了

当我注释掉startTimer()函数中的handler.post()和blink()时,JUnit测试再次开始工作。我似乎找不到任何解决办法。有人能帮忙吗?

我修好了

我做了很多改变我认为这是主要的改变:

handler.postDelayed(this, 0);

也不确定是否有帮助,但万一我也这样做了:

handler.post(runTimer);

我修好了

我做了很多改变我认为这是主要的改变:

handler.postDelayed(this, 0);

也不确定是否有帮助,但万一我也这样做了:

handler.post(runTimer);