Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to run two FOR loops at the same time
    primarykey
    data
    text
    <p>I´m working with accelerometer and the first code is Shake detector: (Code1)</p> <pre><code>if (sensor == SensorManager.SENSOR_ACCELEROMETER) { long curTime = System.currentTimeMillis(); long now = System.currentTimeMillis(); //********************************************************************** if ((now - mLastForce) &gt; SHAKE_TIMEOUT) { mShakeCount = 0; } if ((now - mLastTime) &gt; TIME_THRESHOLD) { long diff = now - mLastTime; float speed = Math.abs(x + y + z - mLastX - mLastY - mLastZ) / diff * 10000; if (speed &gt; FORCE_THRESHOLD) { if ((++mShakeCount &gt;= SHAKE_COUNT) &amp;&amp; (now - mLastShake &gt; SHAKE_DURATION)) { mLastShake = now; mShakeCount = 0; if (mShakeListener != null) { mShakeListener.onShake(); } } mLastForce = now; } mLastTime = now; mLastX = x; mLastY = y; mLastZ = z; </code></pre> <p>With this i get message, when tho phone is shaked: (Code2)</p> <pre><code> mSensorListener.setOnShakeListener(new OnShakeListener() { @Override public void onShake() { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "Shake!", Toast.LENGTH_SHORT).show(); } }); </code></pre> <p>I have also for loop for saving accelerometer values x,y,z into array every 2 secons: (Code3)</p> <pre><code> if (lastUpdate == -1 || (curTime - lastUpdate) &gt; 2000) { lastUpdate = curTime; x = values[0]; y = values[1]; z = values[2]; for (int column = 0; column &lt; 3; column++) { if (column == 0) { p[row][column] = values[0]; } if (column == 1) { p[row][column] = values[1]; //yacc.setText("Os X: " + p[row][column]); } if (column == 2) { p[row][column] = values[2]; //zacc.setText("Os X: " + p[row][column]); }} if (row == 0) { xacc.setText("Os X: " + p[row][0] + " " + p[row][1] +" " + p[row][2]); } if (row == 1) { yacc.setText("Os X: " + p[row][0] + " " + p[row][1] +" " + p[row][2]); } if (row == 2) { zacc.setText("Os X: " + p[row][0] + " " + p[row][1] +" " + p[row][2]); } if (row == 3) { z2acc.setText("Os X: " + p[row][0] + " " + p[row][1] +" " + p[row][2]); } if (row == 4) { z3acc.setText("Os X: " + p[row][0] + " " + p[row][1] +" " + p[row][2]); } row++; if (row == 5) { row = 0; } </code></pre> <p>Code3 is never ending and code1 is shake detector. How can i run it together, maybe with threads (how) or anything else?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload