Persisting informations on the watch screen (WatchFace)

Hi there,

I'm getting there! For the first time this morning I got my watchface installed on my Fenix 6x. It looks good, pretty happy of the result.

I see all the info I retreive via the Background event is not persisted if I change to another screen and come back to it.

Any idea on how to solve this?

Nico

  • in onBackgroundData I save what's need using Application.Storage.setValue() and for a WF, in getInitialView do a Application.Storage.getValue() with the same key.  If you do the getValue() in the AppBase's initialize or onStart() that eats into the space available in the background.

    When doing the getValue() make sure you handle null.

  • Hi Jim, 

    Thanks for your reply.

    What do you mean by "When doing the getValue() make sure you handle null."?

  • If the key doesn't yet exist in storage (the first time you run), when you do the getValue() on that key, you'll get "null".

  • OK. I guess it should be fine as I trigger the display only when the parsing function is completed.

    When I do a 

    var MaxSurfDisplay = Application.Storage.getValue("MaxSurfDisplay"); 

    in getInitialView(), this variable is not seen from MyWatchFaceView.mc

    It throws a MyWatchFaceView.mc:129:  Undefined symbol "MaxSurfDisplay" detected.

    GetInitialView returns [ new MyWatchFaceView() ];

    Note : I do the  Application.Storage.setValue("MaxSurfDisplay", MaxSurfDisplay); in the parsing function, called in onBackgroundData

  • It seems that the variable created in getInitialView and populated by Application.Storage.setValue(); can not be reached by View.findDrawableById("SurfSizeValue").setText(MaxSurfDisplay); from View.mc

    I removed the creation of MaxSurfDisplay as global since the whole point is to avoid using this solution... it makes sense, right?

  • Ok I understood how it works. Thanks!! :)

  • Hi Jim,
    So I made further investigations and found that the information retreived by the webrequests in the background, once parsed and stored, are not updated in the view.
    It was kind of tricky to figure out since the display of the previous graph is persisted by using Application.Storage, and the graph changes every 24 hours only.

    In the onBackgroundData function, I call WatchUi.requestUpdate after calling the parsing / storing function. I was expecting this to work but it doesn't.

    The tests I made is over-writting the rectangles height to a constant value. This over-writting is made in the app, triggered by a temporal event calling the background.

    I only see the result of this change when stopping the simulator and running it again which makes me think the fresh data is stored but not displayed.

    Any advice?

    Thanks in advance,

    Nicolas

       function onBackgroundData(data) {
    	    	counter++;
    	       //Sys.println("Data received by foreground app " + data);
    	       //Sys.println("Returned : " + data);
    	       //Call prep and display
    	       
    	        onJsonData(data);
    	        WatchUi.requestUpdate();
    
    	        var now = Sys.getClockTime();
        		var LastUpdateTime = now.hour+":"+now.min.format("%02d");       
    	        //Storage of LAST UPDATE TIME
    			Application.Storage.setValue("LastUpdateTime", LastUpdateTime);
    			
    	        App.getApp().setProperty(OSDATA,bgdata);
    	        
    	       
    	    } 

  • Add println calls (with the data) at points in your code to see what's going on.  for things like setPropetry, getPropery, onBackground data, when you use the data in your view, etc.

    I'm not sure what you mean by over-riding the data.  In onUpdate, you do clear the dc (dc.clear()) correct or are you using layouts?

  • Hi Jim,
    When I say "overwriting" I mean writing a fixed graph height in place of the data I'm retreiving through webrequests. This way I can differenciate what is persisted from what is freshly updated in the view.
    I don't clear the dc at all. I use a layout but for time fields only, the graph is related to the DC only.
    Should I call "dc.clear()" in onBackground, just before calling  WatchUi.requestUpdate(); ?

    Also, all my Application.Storage.getValue calls are made in onLayout but this seems to be called once and only once. This could be a reason why my graph is not update after each temporal event right?

  • You can't call dc.clear() in onBackground as you don't have the dc.  Have you added the println calls to see what's going on?