I have to write an android application which monitors the accelerometer constantly and saves samples in a file. I know how to get the acceleration values and how to write every single sample in a file, without stopping the sampling, but how can I do in order to reduce the number of disk accesses, without stopping sampling? I need some ideas because I don't know from where I can start.
Thank you
Why are you worried about disk access? We are talking about Android so your disk is flash based and the system optimized disk access anyway.
However if you would like to capture your data and provide it to i.e. an Activity and your file is only meant as a permanent storage then I would suggest that you:
- capture your data in a service
- buffer your data in a list
- write it to disk using an async task which is scheduled on a regular basis
- write it to disk when the service stops to make sure you don't loose data
You can share this data by directly accessing the service from your Activity