Is it ok to iterate over getUserActivityHistory in onShow() for battery life?

I want to sum duration of all today's activities and draw it on my simple watchface, but iterating over the filesystem once every minute starting from the oldest activities and going up to current day seems excessive...

May be you can suggest something on this guys?

Have a good day, thanks!

Alex

  • To avoid iteration every minute, add a flag to the program indicating that the iteration has been completed. When you first start it, reset this flag, and set it after the iteration has been completed. After the period you need (for example, after half an hour), reset it again. Perform the iteration with the flag reset.