0
  final Handler handler = new Handler();
    final Runnable timer = new Runnable() {
        @Override
        public void run() {
            // user too late: increment miss counter
            if (++secondmisses >= MISS_LIMIT) {
                //TODO miss limit reached
                finish(); // close this activity
            }
        }
    };

这是我的可运行计时器,不确定是否可以在这里找到解决方案

我想让我的球体在 5 秒内检测到碰撞

如果(在 5 秒内发生碰撞)向上移动,如果他们说没有碰撞,则向下移动

这是我下面的代码

我不确定我还能做些什么

       mRobot.drive(0.0f, ROBOT_VELOCITY);
            handler.removeCallbacks(timer);
            handler.postDelayed(timer, ONE_SECOND);

        this.checkcollision(v, 1); // if there is no collision
        this.checkcollisoon(v,2); //if there is a collision

请帮忙 :)

4

1 回答 1

1

尝试使用CountDownTimer. 像这样的东西:

long duration = 12345;
long ticksInterval = 1000; // 1 second in millis

new CountDownTimer(duration, ticksInterval){
    public void onTick(long remaining) {
        // Do something each ticksInterval millis
    }

    public void onFinish() {
        // Do something after duration millis
    }
}.start();

当您的应用程序中发生某些事情时,您可以设置一个非静态类布尔值并对其进行测试onFinish()以查看计时器期间是否发生了某些事情。

于 2016-05-31T19:22:00.427 回答