0

I develop an android app for my final year project. This app must collect sensor smartphone information from accelerometer, gyroscope and magnetometer and to save them into a file. So far I have done everything, but now I have some problem with sampling rate frequency of sensors, I do not exactly know how to deal with that.

I need a loop that will write to file every 10 milliseconds. I thought about a for loop but I don't know how to write the statement.

I expect to save information to file every 10 milliseconds.

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
  • Don't use a loop, use a Timer instead: https://stackoverflow.com/questions/31268818/time-interval-in-java – CodeF0x Jan 31 '19 at 14:35
  • Looks like at least the accelerometer sample rate won't be exactly what you request, so maybe you could just always remember the latest value from each sensor and write those to file in a `Runnable` which you run in a `Thread`. That would be one potential approach. – Markus Kauppinen Jan 31 '19 at 15:14
  • Thank you for answers. I am going to try to use what Markus recommended, it looks like he explained better than me what I am supposed to do. – Andrei Radovici Jan 31 '19 at 20:46
  • handler = new Handler(); runnable = new Runnable() { @Override public void run() { handler.postDelayed(this, 10); // call functions here } }; – Andrei Radovici Jan 31 '19 at 20:47

0 Answers0