onStart setProperty

Hello,

I have one question. I am trying to work with Properties for a first time. I am able to use setProperty with Activitymonitor distance/calories from onUpdate but I can't find a way to do it in onStart. Is it possible to save activityMonitor info in onStart? My solution looks ok till I use resume later on fenix3...

I tried to use it like:

if(info.elapsedDistance <= 1){
App.getApp().setProperty("startCalories",calories);
System.println("Kalorie: " +startCalories);
}
else.......

Is it possible to do it through onStart? Will it be cleared after "resume later" or not? I need the start value for the whole activity.

Thank you
  • It always helps if you mention what kind of app (watch face, DF, watch-app, widget) but I'm guessing it's a data field with the "resume later" bit, and there you want to make sure that what's in Activity.Info isn't null)

    What I suspect is that in onStart(), the properties haven't been loaded get. (there's kind of a background loadProperties() done at that time they way I understand it, but not sure exactly when). Try doing it in a place like initialize() for your view instead.
  • Oh I am sorry. I forgot to write that I will try to make datafield
  • Do you mean load the data which I want (for example ActivityInfo calories) in "initialize()" and then use onStart to "setProperty" ?
  • onStart() is in your app class.

    What I do is the getProperty() calls in the initialize() function of the main view, and do the setProperty() when something changes I want to save. (generally, again in the view.)

    By trying to use a property in onStart() is too early it seems.
  • I will try it in initialize(). I need the one value saved on start and the second value saved when "resume later" it looks.
  • Through Initialize it works but I don't know how to save the property when user choose "resume later". i Found one information from Travis.Vitek here on the forum but it looks I made a mistake with using it. When I try to change it for the data which I need, there's no data saved after "Stop activity" in simulator

    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);
    }


    Source code is here:

    https://forums.garmin.com/showthread.php?360881-Data-Field-variables-lost-when-you-Resume-Later