Questions related Position and Storage apis

I've found some old answers on the forum, but not entirely what I'm looking for and also not sure about the behavior on newer SDK version(I'm using sdk 3.1 targeting fenix5):

What would be the recommended way to obtain the last Location in a background service for a DataField. I would like to have this data even when GPS signal its not available.

I've been using Position.getInfo() and the accuracy for the value returned is QUALITY_LAST_KNOWN (which is fine).

Does anyone knows for how long the "QUALITY_LAST_KNOWN" value will be available? Is there a better way to do it e.g. using Storage?

Is there a difference between Location from Activity info and the one from Position info? 

About Storage, are there any concerns regarding performance on how often the DataField should read/write? Would be a problem writing on every call of compute() or it should be used only when activity is starting/ending.

Thank you!

  • Few things.

    1) In a background, you can only read Storage, not write it.

    2) "info" as passed to compute is Activity.getActivityInfo(), and there you have currentLocation (and a bunch of other things).  You can access this in a background, with Activity.getActivityInfo().  So for an activity with GPS, no need for Position as you already got it.  And no reason to pass it in Storage, as the background can get it directly

    3) "Last Known" can expire in an hour or more and varies by device.

    4) if Activity.getActivityInfo().currentLocation is null, and if you want a fall back, and that would be in Storage.  As far as writing that, you don't have to do it every second, but maybe in onStop().  But with onStop(), you want a gate there so it only does it with onStop() in the main app, and got the background.  But you also want to delete the Temporal Event at the same time anyway.  So in onStop(), if you have a surrentLocation, save it to Storage.

  • 1) In a background, you can only read Storage, not write it.

    This is not necessarily true. With ConnectIQ 3.2.0 we added the ability for background processes to create, update, and delete values in Application.Storage. It isn't really documented, but the functionality is there and is demonstrated in the BackgroundTimer sample app.

  • That's right!  I recall something about that!

    I stand corrected. 

    The target mentioned in the original post was a f5, so still 3.1 though.