I am trying to add the ability to restart an activity again in my app (it's a triathlon app where I would like to trigger the end of the first sport and have it start the next activity automatically, but be able to manually reset the start time if I miss my target transition time).
I am using source code from lucramod's awesome TriathlonDuathlonAquathlon. In which the following functions control the start and end of each activity.
function onBegin() {
if( disciplineSession == null ) {
var logtxt = Lang.format("Starting $1$ ($2$ :: $3$)", [stageNames[currentStage], stageSports[currentStage], stageSubSports[currentStage]]);
Sys.println(logtxt);
startTime = Sys.getTimer();
if( TriData.currentDiscipline == 0 || TriData.currentDiscipline == 2 || TriData.currentDiscipline == 4 ){
disciplineSession = Rec.createSession( { :name=>stageNames[currentStage], :sport=>stageSports[currentStage], :subsport=>stageSubSports[currentStage] } );
if( disciplineSession != null )
{
var starttrue = false;
do{
starttrue = disciplineSession.start();
}
while(starttrue == false);
}
}
}
}
function onEnd() {
Sys.println("Saving");
endTime = Sys.getTimer();
if( TriData.currentDiscipline == 0 || TriData.currentDiscipline == 2 || TriData.currentDiscipline == 4 ){
if( disciplineSession != null && disciplineSession.isRecording() )
{
var stoptrue = false;
var savetrue = false;
do{
stoptrue = disciplineSession.stop();
}
while(stoptrue == false);
do {
savetrue = disciplineSession.save();
}
while( savetrue == false );
disciplineSession = null;
Ui.requestUpdate();
}
}
disciplineSession = null;
}
I have added the function :
function onReset() {
Sys.println("Resetting");
endTime = Sys.getTimer();
if( TriData.currentDiscipline == 0 || TriData.currentDiscipline == 2 || TriData.currentDiscipline == 4 ){
if( disciplineSession != null && disciplineSession.isRecording() )
{
var stoptrue = false;
var discardtrue = false;
do{
stoptrue = disciplineSession.stop();
}
while(stoptrue == false);
do {
discardtrue = disciplineSession.discard();
}
while( discardtrue == false );
disciplineSession = null;
Ui.requestUpdate();
}
}
disciplineSession = null;
}
I manually call onReset using a button press before triggering onBegin. This seems to work fine in the simulator but creates corrupt files when run on a watch. The corruption occurs with the reset activity and no further activities are recorded, although the app on the watch does continue to display activity time etc.
My question is, is there anything obviously wrong with the way I have finished and discarded the activity recording. My current thought is that the the corruption is caused because there is not enough of a delay between resetting the activity and starting the new one. In which case is there a better way of resetting the start time of an activity?
Thanks,
Jon