So I have an app where most of my settings are done directly on the watch. This works great.
I wanted to test having a couple of settings done from the phone, so I added a settings.xml file with:
<settings>
So I have an app where most of my settings are done directly on the watch. This works great.
I wanted to test having a couple of settings done from the phone, so I added a settings.xml file with:
<settings>
OK I have some elements of an answer.
I have some other properties that are amended directly from pickers within the watch app. And upon settings change, I load the property values that are set via pickers within the watch app to variables within a MySettings class instance (sometimes with things like units translations involved), so I can refer to the MySettings variables in the rest of the app, rather than going back to the properties every time. So I do use getValue(), but only for the properties that are not exposed to Connect IQ app via Settings.xml (that have always worked up to now).
This works fine. However, I think that when exposing one new field to Connect IQ settings via Settings.xml, and when saving from Connect IQ, Connect IQ messes with the values of the other properties (the ones not exposed via Settings.xml)! And somehow breaks them (probably tries to copy them as is, but somehow fails). This only happens on the watch+phone, not in the simulator.
The reason I can say this is that I have one setting (set within the watch app via picker) which is the background color. There is one instance where I managed to save my additional field (that doesn't do anything yet, and is never read in the watch app) within the ConnectIQ app without crashing the phone app, but once done the background color of the app changed!
It actually makes me think that Garmin calls the onSettingsChanged() before it has fully finished writing the amended properties?
That would be extremely unfortunate...
Yeeeah I think I can confirm corruption of properties that are not set within Garmin IQ app is happening. I used onSettingsChange() to separate my Connect IQ app set property and the rest of the properties:
1. If the connect IQ app set property "userLivetrackUserName" has changed, then do nothing
2. else (e.g. one of the other properties has been changed directly within the watch app, via picker), load my properties into variables as usual.
This makes saving the property from the Connect IQ app doesn't crash the app anymore. However, once that happens, my other properties are corrupted and can't be read to my variables anymore (I suspect type issues). So I guess I need to add a type check on all my other properties. I'll try that...
Aaand I think fixed it. So here's what was happening:
- For my existing properties, the way I worked was that type was guaranteed, nullness was not. So I was just checking for nullness, not type.
- HOWEVER when adding even a single property that can be changed via ConnectIQ and using ConnectIQ to amend it, then this affects all the other properties, and in particular their types (Number properties have then a bad habit of returning Floats). So you then *must* implement the type check detailed in this FAQ for all properties, including the ones not set via ConnectIQ: https://forums.garmin.com/developer/connect-iq/w/wiki/4/new-developer-faq#settings-crash