Session.save not working

Hello,

I´m recording an activity in my App. It seems to work on the Simulator and also on my vivoactive.
Start the App, push Rec (vibrates), record some Minutes (steps, time & heart rate), then push Rec again (vibrates), push back, App asks if I´d like to save => Yes. Application Close.

But there are several misbehaviour appearing randomly:
  • After some time, the vivoactive freezes. When I restart it, there is an unreadable activity in the protocol
  • Nothing happens and there is no activity in the protocol
  • I start f.e. the running App. It shows a red border, which should indicate, that there is an open session. If I close the App, I can confirm canceling it. A progressbar appears and nothing happens until I reboot the device.

Whats going on there?

My code:
function initialize()
{
if(hasRecording == null)
{
hasRecording = Toybox has :ActivityRecording;
}
}
function ToggleRecording()
{
if(hasRecording)
{
if((session == null ) || (session.isRecording() == false))
{
session = Record.createSession({:name=>"Squash", :sport=>Record.SPORT_TENNIS});
session.start();
recorded = true;
Sys.println("Recording started");
}
else if((session != null) && session.isRecording())
{
session.stop();
}
}
}

function storeRecording(save)
{
if(hasRecording)
{
if(session != null)
{
if(session.isRecording())
{
session.stop();
}
if(save)
{
session.save();
}
else
{
session.discard();
}
}
}
Sys.println("Store Recording: " + save);
}

When the Application will be closed, I throw a confirmation dialog (Save/Discard). then I call storeRecording() with the result and afterwards, I return true to close the dialog.
The App in the simulator freezes (so I guess it closed properly) and on the device, I return to the Application overview.

It´s my last stage to release my App :(
  • I don't know how I managed to miss this post, but anyway... It doesn't look like the problem you are experiencing is related to recording at all. It is more likely to be related to your view management code. To that end, I should mention that returning from the confirmation delegate's onResult will dismiss the Confirmation, but it does nothing to exit the app. If you want to exit the app, you must either explicitly call Ui.popView() to remove the last view on the view stack (usually the one returned from App.getInitialView()), or you must return false in response to a KEY_ESC or onBack() key event. It sounds like you are doing neither of these things.

    In case you're looking for some free feedback, here are some notes on your code...

    In ToggleRecording() you call createSession() if session is is null or if session.isRecording() is false. At least on some devices, and in the simulator, you will get a crash if you try to call createSession() when there is already an existing session in progress. I think I'd change that code to...

    if(hasRecording) {
    if(session == null) {
    session = Record.createSession({:name=>"Squash", :sport=>Record.SPORT_TENNIS});
    }

    if (session.isRecording())
    session.stop();
    }
    else {
    session.start();
    }
    }


    Second, in storeRecording() you do two things; you stop the recording if not stopped, and you save or discard the recording. Normally on a Garmin device, you wouldn't be able to save or discard a recording unless it was already stopped. The stop() and associated condition should be unnecessary assuming that your app follows what users are likely to consider normal.

    Travis
  • Hello Travis,
    thank you very much! I did the changes as you suggested. The stop() is already unnecessary, because I dont´t let the user quit the application during the recording.
    Initiating the session only once seems also very plausible!

    Your other advice with returning false or popView is (for me) really a pain.
    Returning false will not work, when you are using a confirmation dialog. So the dialog itself have to popView the parent view and return "false" to close itself. That doent´s work either, because you are poping the highest view, which also is the confirmation, not the parent view. So I have to popView twice, which until SDK1.1.1 produced an error (while I´m typing I uncommented that and it seems to work within the simulator).
    If you are juggeling with views, I really wish for a popAll or App.Quit functionality.

    I´m a developer in ERP-Systems, .Net, JS and even coding around with an Arduino. But the View-popping seems to strange to me :(

    Thomas