i'm working on a datafield now and had no idea about this behavior until i tested today on a long ride with two devices (1) a garmin watch, I used the "resume later" functionality after our lunch for the short ride home (2) an edge unit where I created two separate recordings before and after lunch. It was confusing to me that my datafield stats for the "resumed-later" activity matched the part two edge recording of the ride home; after searching the forums I realize now that my data field stats are getting reset. As far as I know this still isn't covered in the documentation, I agree it definitely should be! I think the datafield lifecycle events in general could be fleshed out in the docs and this would be very helpful.
Yeah, it looks like Resume Later will never be addressed in the docs or the API. (The :resume key in AppBase.onStart's state dictionary does not refer to "resume later", but instead resume from suspend on newer devices which have "multitasking" via the "task switcher").
But if you want to handle it in your data field, I can envision the following approach:
- in your datafield's AppBase.onStop(), save the app state
- the next time the datafield runs, check whether ActivityInfo.timerTime is non-zero [*] at startup. If so, assume that the datafield is part of an activity that was resumed later and restore the app state. If not, clear the previous app state
[*] or substitute the heuristic of your choice. Maybe you want to use elapsedtime or elapsedDistance instead. And maybe you want to have some threshold other than 0, like 5, 10, or 30 seconds, to avoid any possible false positives. (Maybe there's some crazy edge case where the user starts the timer asap, and the data field sees a value slightly greater than 0 the first time it reads timerTime.)
I haven't actually tested this approach myself.