Multi-Sensor Android Logging

707 views Asked by At

I am new to Android and I try to do a simple app that can log accelerometer, Gyro and GPS into a single csv file (background) so I could analyze the data later. After some digging in google, all the info I get are kinda old and some are not really working.

So, the questions are:

  1. If I do all the task in UI thread like this https://stackoverflow.com/a/4343827/2985850, I wonder is there a delay between each sensor logging? As I want all the sensor run concurrently at the same sampling rate.

  2. So far, I notice there are 2 ways to accomplish this: using multi-threading or Service. But, (correct me if I'm wrong) the service is also running on UI thread so that mean if I do it the Service way, the logging process also run in a single thread and this might probably cause some delay on the logging process between each sensor?

If there is a better way to accomplish this or any good example feel free to drop 'em here Thanks! :)

1

There are 1 answers

7
fakturk On BEST ANSWER

According to my experience I will try to answer your questions

  1. Yes there is time difference between different sensor reading, in that case you have 2 options

    a - You can also put a timestamp on your cvs file (you can get it by event.timestamp)

    b - You can get sensor readings with a static frequency instead of SensorManager.SENSOR_DELAY_GAME (you can give time here as a ms, for example if you write 10 instead of SensorManager.SENSOR_DELAY_GAME your device get sensor reading every 10 ms (100Hz))

  2. I also use it as a service and did not get any delay

Also I want to add one more small thing, if you want to get data for a small amount of time you can always use System.out.println() and it is faster than writing to a file