You should be able to save your data App.onStop(state) and read them back in App.onStart(state).
function onTimerPause() {
_pauseCount += 1;
}
function onTimerReset() {
_pauseCount…
However, in the context of the onStart event I don't believe I have access to the activity's info properties - or do I?
The difference between the two is that they both start at 0 when you start an activity. Elapsed time continues to run until the activity is saved or discarded.
However, timerTime will stop when you pause…
using Toybox.Application as App;
using Toybox.WatchUi as Ui;
enum {
PAUSE_COUNT_PROPERTY = 1
}
class MyDataField extends Ui.SimpleDataField
{
hidden var _pauseCount;
function initialize() {
SimpleDataField.initialize();
_pauseCount = 0;
}
function compute(info) {
return _pauseCount;
}
function onStart(app, state) {
_pauseCount = app.getProperty(PAUSE_COUNT_PROPERTY);
if (_pauseCount == null) {
_pauseCount = 0;
}
}
function onStop(app, state) {
app.setProperty(PAUSE_COUNT_PROPERTY, _pauseCount);
}
function onTimerPause() {
_pauseCount += 1;
}
function onTimerReset() {
_pauseCount = 0;
}
}
class MyApp extends App.AppBase
{
hidden var _dataField;
function initialize() {
AppBase.initialize();
_dataField = new MyDataField();
}
function onStart(state) {
_dataField.onStart(self, state);
}
function onStop(state) {
_dataField.onStop(self, state);
}
function getInitialView() {
return [ _dataField ];
}
}
You should be able to save your data App.onStop(state) and read them back in App.onStart(state).
You should be able to save your data App.onStop(state) and read them back in App.onStart(state).
function onTimerPause() {
_pauseCount += 1;
}
function onTimerReset() {
_pauseCount = 0;
}
}
You can determine when a new activity starts by looking at average speed. If it is zero, you have a new activity.
Correct. Check average speed in your compute function and clear them when average speed is zero or null.
However, once I've saved values, they seem to persist even after the activity has subsequently been resumed and then terminated (eg. "Save", "Discard").
Furthermore, the two timer-related events in your code sample (shown above in red) don't seem to be functional (I'm using an Epix)
Stated another way, the object store doesn't seem to reset implicitly when I stop an activity (or start a new one), and I haven't figured out how to tell the difference between an "onStop" that occurs in a "Resume Later" situation vs. one that indicates the activity has ended. Am I missing something obvious?
Correct. Check average speed in your compute function and clear them when average speed is zero or null.
Is there some reason that you can't you call Activity.getInfo()? Also, average speed can be zero if GPS is off, so this isn't a reliable way to detect an activity reset.