dimanche 19 juin 2016

If statement, not carrying much for true or false in Android Activity

I'm defending my Bachelor tomorrow. There is some issues in my code. I'm creating a countdowntimer at specific times & it should also not be creating multiple timers because I'm using an if statemet:

if (norm[j] / 9.5 < normT) {

                            if (!isRunning){ // Only starting 1 timer at a time
                                Log.d(TAG,"Checking Velocities"); // Debugging
                                final counterClass timer = new counterClass(3000, 10, norm, diff);
                                timer.start();
                            }

The above is part of the function which instantiate a timer. This isRunning boolean should only be false when the counter has finished:

public class counterClass extends CountDownTimer {

    double[] nor = new double[120];
    double[] dif = new double[119];

    public counterClass(long millisInFuture, long countDownInterval, double[] norm, double[] diff) {
        super(millisInFuture, countDownInterval); // Duration & how often onTick should be called
        isRunning = true;
        nor = norm;
        dif = diff;


    }

    @Override
    public void onTick(long millisUntilFinished) {
        //listFall(); // Adding accelerometer data to fall list array List each time its called
      vCheck(nor,dif); // Calculate velocity approximation every 10th millisecond.
    }

    @Override
    public void onFinish() {
      isRunning = false;
    }
}

These are the only times I'm using the boolean, other than when I'm declaring it, in the mainactivity class. When I look at the Log.d output it will keep outputting "Checking Velocities" when certain criteria has been met. And this is what's very confusing to me.

Aucun commentaire:

Enregistrer un commentaire