user1781027
user1781027

Reputation: 73

How do you make an android application wait?

I'm trying to make a pedometer application with Android using only the accelerometer to gather data. I gathered a lot of raw data from the phone and found certain patterns to constituted a step from my gait and created 3 booleans to model how one step would look like to an accelerometer.

public boolean beforeStep(float y)
    {
        if(y > 1.5 && y < 3){
        return true;
    }
        else
        {
        return false;
        }
    }

public boolean duringStep(float y)
{
    if(y > 3 && y < 5){
        return true;
    }
    else
    {
        return false;
    }
}

public boolean afterStep(float y)
{
    if(y > 1.5 && y < 3){
        return true;
    }
    else
    {
        return false;
    }
}

if(beforeStep(accel)){
    if(duringStep(accel)){
        if(afterStep(accel)){
            stepCount++;
        }
    }
}

At first I had run these booleans in my onSensorChanged() method, but I realized that this meant that it would pass the same acceleration value to all three booleans, so the program would never recognize a step. How do I make Android wait, say 10ms, between each boolean check so that the acceleration value updates?

Also, if there is a more accurate/efficient way to go about counting steps using raw acceleration data, please let me know!

Upvotes: 0

Views: 325

Answers (2)

iTech
iTech

Reputation: 18460

There are many ways to make you application wait, for example by using wait/notify, see example or Semaphore

See this Pedometer application it is doing exactly what you are trying to achieve

Upvotes: 0

kevinsa5
kevinsa5

Reputation: 3411

You could store the state in an int and keep track of which part of the step you're in (before = 1, during = 2, after = 3). Then you could do something like

onSensorChanged(){   
  if(state == 1){
    if(duringStep(accel)){
      state = 2;
      ...
      return;
    }
  }   
  else if(state == 2){
    ... 
  }
}

Upvotes: 1

Related Questions