state of session after save()

In my watch app, I wish to be provide the user with the ability of multiple Activity FIT files (sequentially, not simultaneously), so I'm using the session methods to manage the state of the session.

At the start, I invoke mySession.start(), and on receipt of user request to stop this recording I call; mySession.save(). 

It's not clear from the docs how I can determine the state of the session, as a subsequent call to mySession.isRecording() causes 

Error: System Error

Details: a class method was invoked on a Session that is no longer valid

I'm not clear on the state of my session after save. The doco, tantalisingly, states: "Complete the session by storing the FIT file on the file system."

Given that, as the error message states, isRecording() is not  a valid method on a Session that has been saved, are there any methods that I may use to determine its state, or do I have to manage my session's state myself? 

  • Ok, for a simple session you

    1. create the session
    2. start recording
    3. stop recording
    4. save/discard recording

    The session is really no more after 4,  After 3, you can do another start, as that's how a pause is handled.

    The error you see is likely that the session is no longer valid (it's after #4)

  • Yes that's what I'm seeing, but what is the state of the session after #4? The session is not null, but in some different state. So my Q remains :

    "are there any methods that I may use to determine its state, or do I have to manage my session's state myself? "

  • After #4 the session is in an invalid state. Technically, I think it should become invalid after Session.save() or Session.discard() have returned true. At that point calling methods on it should result in an error.

    If you just set the session reference to null after you save/discard it, you can use a null check to see if it is safe to access the session without having to maintain any additional state.

    We can't set your session to null for you. This is something that you have to do yourself.

  • What I take from that is that after a session.save() returns true, there are no methods available on the session, so setting the reference to null is the way to go.

    Thanks

  • Complete the session by storing the FIT file on the file system.

    It may be interesting to add that the session is actually already saved before doing the session.save (if you hard shutdown your device while recording or after issuing a session.stop a fit file of the activity will be there).

    In my Peter's Pacer (The App) app I only save the activity upon exit of the watch app as at that point I'm sure I won't resume the activity any more.

  • Former Member
    0 Former Member in reply to peterdedecker

    The file is incomplete before calling session.save(), but shutting your device down would close the application, which will (effectively) call save() on the active session object if there is one. If you shut the watch down without allowing the software to power down properly, you would end up with a incomplete .fit file. (It isn't really possible to do that though. You'd have to open it up and yank the battery, or have a hardware failure.)