Migrate from AppBase.getProperty() to Storage.getValue() ?

The AppBase.getProperty() is deprecated now. So I tried to migrate to Storage.getValue()

The docs are a bit uncleart for me...
https://developer.garmin.com/connect-iq/core-topics/persisting-data/

So I tried to read the app settings from Storage.getValue() first. If not found I try to get "old" values with AppBase.getProperty() and migrate the data into the new storage with Storage.setValue().
So far this is working.

But the app settings done in ConnectIQ app seems to be stored still in AppBase, not is Storage. So changing the settings in ConnectIQ app has no effect if the Storage object has already a value set for the property id. Then the "old" storage is not read in the app.

How can I force the ConnectIQ app to set app settings into the Storage memory?

  • You don't need to migrate the properties. On newer devices that have the new apis use them, on older devices that don't have the new apis use the old ones. Unfortunately you won't be able to get rid of the stupid warning if you still want to compile for old devices as well. You can vote on the bug report though: forums.garmin.com/.../sdk-4-2-0-beta-1-won-t-compile-appbase-getproperty and forums.garmin.com/.../bug-compiler-4-1-6-included-broken-parts-of-the-4-2-0-beta-1-with--l-3

  • I'm really sure the data is not migrated.

    If the data was stored with AppBase.setProperty() before, I won't get this value using Storage.getValue(). I get "null" as result because it was not set in Storage object before. That's why I read the old way as migration path.

    And I check in the app if the device is able to use Storage:

             if ( Toybox.Application has :Storage ) {
                val = Application.Storage.getValue(name);
                if (val == null){
                    val = Application.getApp().getProperty(name);
                    if (val != null){
                        Application.Storage.setValue(name, val);
                    }
                }
            }
            else{
                val = Application.getApp().getProperty(name);
            }

    This way I can use storage device dependent.

    But there is still the problen that changing the setting in ConnectIQ app, only the "old" storage is updated.

  • Understand that getProperty() can be used to access the object store ("storage") as well as "properties" (app settings).  With the getValue() calls, you use Storage.getValue() to access the object store and Properties.getValue() to access app settings.  

  • Thanks, Jim,

    so this should be:
             if ( Toybox.Application has :Properties ) {
                val = Application.Properties.getValue(name);
    to read the app settings with the new API?

    So I should differentiate in the app:
    - is it app settings: use Application.Properties.getValue(name);
    - is it some storage only stored and read by the app (bearer token etc).: use Application.Storage.getValue(name);

    Is this the preferred way?

  • The "new" api isn't really that new (I've been using it for years), and yes, to get App Settings, use Application.Properties.getValue() .  Application.Storage can only be read or written by your app.