i have build a simple Android App. A Thread is collecting data, sleep 500ms, collecting and so on. The app should do this endless (until I stop it).
Now the thread run in a foreground service (in the activity and in a background service android kill the thread/service after a couple minutes).
If some data collected, the thread save them in a text file. (It collect 120 values in 1 minute, forms the mean and save this with timestamp).
When I am looking in the textfile, there data for 1-2 hours, every minute - like i want it. But then absence data for 10 minutes, then for 30 minutes are data for every minute, then absence data for 2 hours and so on.
I can not figure out: - if android sometimes not save the data, - or is it to stupid to continuously sleep every 500ms (sometimes sleep 2 hours?), - or android paused the hole service (randomly) - ...
Is there a better way to collect data periodically?