Complete
over 4 years ago

CIQQA-164

F5 can't save to Storage from Background (while F6 and others can)

Fénix 5 serie can't Toybox.Application.Storage.setValue from a Background process => throws an Exception. 

Fénix 6 and others like FR245 can. 

  1. It's not documented
  2. Bug or feature? 
  3. How to test programmatically if the device can saving to Storage from background without always needing to throw and catch such exception that is dirty, ugly and inefficient?
  • The exception is: 

    Error: Unhandled Exception

    Exception: Background processes cannot modify the object store

  • That will be it. Thanks for sharing.

    Can you please update it to the API documentation?

    Others might hit this exception on production, because you don't enable Background process testing and it's not clear. 

  • I do get user feedback regarding issues in their F5 and FR935 (just to name some) that I cannot reproduce in a F6 or FR945. Since I don't have any "older" generation physical test devices, I cannot corroborate the user reports of issues they experience. In the simulator it's not reproducible. All devices have 3.2.x compatible firmware.

    There seems to be CiQ implementation differences between e.g. F5 and F6 that are not reproducible in the simulator. Maybe having a better, more accurate and configurable simulator would be the best way to help in developers tackle these "inconsistencies".

    Anyway, according to the docs you should be able to write to storage from background context from CiQ 3.2 onward. Best solution is a CiQ-side bug-fix.

    Maybe you need to try-catch that storage call, and possibly abort it when its not possible to write (or throw your own exception with more info). Or maybe there's something else you could do...

    Sounds like your hitting the limits of what can be done, that is exciting!

  • True, it is "now" in the developers guide, but that limitation should be clear in the Storage API documentation. These background context limitations are never clearly stated. There are others that I ran into via trial and error e.g. loading String resources in background context not being supported for older CiQ versions, I found no reference to that in the API docs. Thankfully I was clarified in the Forums.

  • What exception is it throwing? If it's an ObjectStoreAccessException then it is because the device does not support 3.2.0 or later.

    The API docs don't mention 3.2 and earlier background limitations, but it is in the developers guide. (https://developer.garmin.com/connect-iq/core-topics/persisting-data/)

    Connect IQ 3.2 introduces the ability to access the Application.Storage module from background processes. The background process can 
    modify storage using Application.Storage.setValue(), Application.Storage.deleteValue() and Application.Storage.clearValues(). When the
    storage is written from the background process, Application.onStorageChanged() callback will be invoked for the foreground process if
    the background and foreground process are active at the same time and vice-versa. The application would then have to reload data from
    storage to reflect updated information.