BackGround (WF) and updated OS Storage

HI,

i'm playing around with CIQ, trying to push my watch to its limits...

I have a problem with var between app and BG.

So i write OS storage data to get it read in BG.

It works perfectly in simu, while on my watch (saw it thanks to -many- println ) the data is only get once, never the last data updated in the view.

(I have 2 differents URL in my BG for a webrequest, depending on time and others tricks)

I 'm making a getProperty in onTemporalEvent, not working. I put my getProperty in BG initialize(), idem.

So i put this in onStop() :

    if ( Toybox.System has :ServiceDelegate ) {
            Background.deleteTemporalEvent();
            Background.registerForTemporalEvent(new Time.Duration(intervalWebRequest.toNumber() * 60));
        }

and it seems to work.

I do not like this way of doing it,

so where am i missing something, does the BG as soon as starting fully disconnected from the OS (has its own copy of it??)

May it be some bug, is there no way to get updated data via OS, in the BG?

thanks for any help !

  • make sure you are only writing to Storage from your main app and not the background.  This might not be clear, as some functions in your AppBase are called only for the main app, some only for the background, and some for both.

    getInitalView() is only called for the main app, getServiceDelegate() only by the background, while things like initialize(), onStop() and onStart() are called by both for example.

    Best thing to do might be to add a bunch of println calls to see what's running in the forground/background.

    Using the Storage or settings is the only way to get info into the background, as vars are not common between the main app and the background.

  • thanks Jim.

    Yes, i'm only writing in the app/view, with a flag when BG is running to avoid updating storage while reading it in BG.

    What i do not understand is why my getProprety is getting old values in BG, not the last updated one ?

    (but It's perfectly working in simu).

    I already put a println in each call , to see which one is called and when...

    What i will try :

    -Put more println, in each call, to display the flag value . I may see when this is the old one.

    - Use setValue instead of setProperty (will slow the app but why not?)

    It sounds like BG took a picture of OS data (when init ?) and work with this copy.

    I have to find when exactly , (i guess)

    (at this time, a stop/start BG in onStop seems to "reload" OS data)

  • Try adding println calls showing what you save and what you read (with a time stamp).  Also, on a real device, things might not run when you expect.  For example, the background won't run if you are running a CIQ device app.

  • thanks.

    I think the timestamp added to the value is the best way to see what happens in BG and in App...

    I Will try it and let you know...

  • Hi Jim,

    here are some println :

     in onUpdate:  at 11:45:0
    ********* drawInformation ********   mRequestType    =2*** registered at 11:42:47
    Background: ****background Init **** mRequestType   = 0*** registered at 11:38:47
     in onUpdate:  at 11:46:0
    ********* drawInformation ********   mRequestType    =2*** registered at 11:42:47
     in onUpdate:  at 11:47:0
    ********* drawInformation ********   mRequestType    =2*** registered at 11:42:47
     in onUpdate:  at 11:48:0
    ********* drawInformation ********   mRequestType    =1*** registered at 11:45:47
     in onUpdate:  at 11:49:0
    ********* drawInformation ********   mRequestType    =1*** registered at 11:45:47
     in onUpdate:  at 11:50:0
    ********* drawInformation ********   mRequestType    =1*** registered at 11:45:47
    Background: ****background Init **** mRequestType   = 0*** registered at 11:38:47

    (0 is stock  / 1 is weather / 2 is weather Forecast )

    It may confirm that getProperty, in BG, access a copy of data and not the "real" App data.

    Maybe Garmin did in that way to avoid read/write error to the .set file, but since we can not write in BG, i do not understand.

    the only way i can read last values is in stopping BG and starting it again. That's not a nice way .

    (I will try to put it in BG initalize(), since onStop could never be called if no cnx when starting watch !)

    Can we consider it as a bug ??

    thanks.

  • Are you using Storage or settings?  With storage/object store, the .set file isn't involved.

  • oups sorry, it is a mistake i made in unsing the name ".set".  Storage are in memory but maybe Garmin make some file somewhere (like out.bin or something else?)

    It works with settings since they are not changed very often and a requestUpate is done in onSettingsChanged().

    (that's maybe a way to update BG stored datas in my case? -> WatchUi.requestUpdate() )

    I am using storage via set/get Property... maybe should i use set/get Value...

  • So...

    I was using storage with setProperty in App, and getProperty in BG. No way to have updated data except with stop/start BG.

    I am now using storage with setValue in App and getValue in BG, and it seems to work with updated value.

    Should we consider it a bug since i did not find anywhere in the doc that the BG Storage data is only a "pic" of App storage ?

  • The object store (the old storage) typically is only saved when the app exits, but I'd thought it was saved more often when backgrounding is involved.  But you found the solution - use Application.Storage

  • App Storage is saved as soon as setValue is done, and usage recommended since CIQ 2.4.

    Object Store  saved only on App.onStop().

    So i understand that datas in BG are only avaliable by reading files. Good to know.

    I think Doc (programmers Guide or Class List background ) could be more detailed about data usage in BG ...

    Thanks Jim for the idea of the timestamp.