I'm developing an app which needs access to 'the last 5 seconds worth of data' for a given sensor. My plan is to store this data somehow, then when I request the data, it'll return any data obtained within the last 5 seconds. I'm not sure how to do this effectively, given that:
Dalvik doesn't like having lots of objects being created, so I can't make an object for each sensor reading which contains the value + timestamp.
I need to be constantly storing new data in some sort of structure, whilst retrieving a specific portion of it.
My only other requirement is that data which is older than 5 seconds should be disposed of. This isn't really critical, but I imagine retaining the data would eat at memory.
I currently have a onSensorChanged
listener set up, so I don't need help with that.
Any ideas?