How to save data in the ObjectStore from a watchface

Former Member
Former Member
Hi there

I'm trying to save some data, in this case a string in a permanent memory, so I can read it back at a later point in time.

As far as I can see, I need to save it in the ObjectStore.

All the tutorials I could find online was implemented as an App instead of a watchface.

I have tried the following code for saving it, but I get a "Symbol not found" error

ObjectStore.setProperty("myKey", "String to save");

Any input is greatly appriciated
  • Look at the ObjectStore sample in the SDK. It first started as only the Object Store, but then with app settings, a second screen was added to also show that.

    The reason being, is they are quite similar. (you use the same calls for both, like setProperty()). The difference is you don't define a property in an xml file for the OS. The OS is stored in a .str file in apps\data and the app settings in a .set file in apps\settings.

    The problem with your call is that you're not using your app. Here's what I mean:
    var app = App.getApp();
    app.setProperty(OS_DATE, osDate);

    Also when you doa getProperty, make sure you check for null (that will be the case if there's not been a setProperty() yet:
    var value = app.getProperty(OS_DATE);
    if(value==null) {
    // handle this
    }


    As far as watch face vs device app vs widget vs DF, it makes no difference as it works the same..

    Now while the OS and app settings are accessed the same way, they really have different purposes (and like I sad, different files). App settings are for things you want a user to be able to modify - colors is a good example, while the OS is for things maintained by the app that the user doesn't change (an example is that's where I save the high and low temp in one of my apps, but also it could be things like the last valid lat/lon that was used to calculate sunrise/sunset)
  • Former Member
    Former Member over 8 years ago
    Great, thanks.

    Got it working now.

    But for future reference, where do I find these samples in the SDK?
  • You have the SDK in a directory on your machine. There is a samples directory in it. The README file in the SDK talks about the sample apps and what they do.

    Also, in the Connect IQ menu in Eclipse, you can just select "samples".
  • Former Member
    Former Member over 8 years ago
    Great, so it was closer than I thought :-)
  • Samples are really the first place to look when you have a question, IMHO. When there's something new in an SDK, there is usually a sample that will demonstrate it before any developer has used it. For example, that was the case when "app settings" came out in 1.2.0 and the ObjectStore sample had been updated and showed how to use it right away, and there was a new SensorHistory sample when that was first introduced.
  • App settings are for things you want a user to be able to modify, while the OS is for things maintained by the app that the user doesn't change

    It seems that the only distinction between app settings and the object store is that app settings can be read/written outside the app in question. Where the data is stored or whether the user can change it seems irrelevant. A read-only property is technically an app setting (it is defined in the xml) that the user cannot change, and there are cases where it might make sense to allow the user to modify data maintained in the object store.

    Travis