More "App Settings" questions for datafields

I'm having trouble getting my complex datafield to reflect/show a setting change after I modify and send it using the app settings editor in Eclipse (says "Settings sent successfully"). I send the updated setting while the datafield is running in the simulator. I've read as many of the other threads about this topic, but they all seem to relate to CIQ apps and widgets.

As far as I can tell my resource file is written correctly, and my .getProperty("maxhr_prop") call in the initialise() function correctly retrieves the default value defined in the resource file as confirmed with a console output "println" and displayed on the datafield in the simulator. Actually I've noticed that modifying the value in the resouce file isn't always updated. The old value seems somewhat sticky. This is on mac.

My datafield code also does a .getProperty call in the compute() function, however the value that I output using both a console output and displayed on my datafield on the simulator never changes from the default value in the resources file (properties.xml).

Here's the resource file
<resources>

<properties>
<property id="maxhr_prop" type="number">165</property>
</properties>

<strings>
<string id="maxhr_title">Maximum Heart Rate</string>
<string id="hr_out_of_range_msg">Max HR must be between 100 and 230</string>
</strings>

<settings>
<setting propertyKey="maxhr_prop" title="maxhr_title">
<settingConfig type="numeric" required="true" min="100" max="230" errorMessage="hr_out_of_range_msg"/>
</setting>

</settings>
</resources>


and the code (this is the "app" class, there is a separate "view" class):

using Toybox.System as System;
using Toybox.Application as App;

class hr_tiz_data {

// public data
var timertime;
var maxHr;
var hr;
var hr_pmax;
var ave_hr;
var ave_hr_pmax;
var zone;
var timer_paused;
const NumZones = 5;
hidden var zoneLowerBound = [NumZones];
var secondsInZone = [NumZones];

function initialize() {
//maxHr = 182;
maxHr = App.getApp().getProperty("maxhr_prop");
System.println("\nMax HR=" + maxHr.format("%d"));
zoneLowerBound = [0, maxHr * 0.77, maxHr * 0.88, maxHr * 0.92, maxHr * 0.95];
secondsInZone = [0, 0, 0, 0, 0];
timertime = 0;
timer_paused = true;
}

function compute(info) {

maxHr = App.getApp().getProperty("maxhr_prop");
System.println("\nMax HR=" + maxHr.format("%d"));

if (info.timerTime != null) {
// Check if user has paused the timer
timer_paused = (info.timerTime == timertime);

if (!timer_paused) {
timertime = info.timerTime;
}
}


- should I be calling "onSettingsChanged()" or is that only for apps and widgets?
- is it expected that datafield App settings are modified while running (i.e. user with GC mobile app), and changes need to be checked for, or should datafields just get the values once at the start?
- if App settings should be checked while running, is there a better place than the compute() function?

Confused - thanks for your help!
  • Is this still a problem with the latest SDK and Eclipse Plugin? If so, I can make sure that it gets reported.
  • Is this still a problem with the latest SDK and Eclipse Plugin? If so, I can make sure that it gets reported.


    I am not sure if it is caused by a space in my path of eclipse workspace (my project name has no space in it, my directory path has), but definitely when I change app settings in Eclipse, my app.onSettingsChanged is not called and settings are not preserved between simulator runs. The workaround to get settings to app in simulator is to 1) run the app, 2) edit the settings, 3) "Edit ObjectStore" in simulator and press OK. The app will restart with new settings applied...

    At least it is how it behaves on my W10 machine on widget project.
  • Can I have another question? Is it still needed to count with the fact that settings properties of type Number can be returned as Strings on Android?

    What I do now is something like:

    var p = getProp("bla");
    if (p != null && p instanceof Number) {
    // process settings
    }


    But if it can still be returned as string, than it is far from satisfactory of course...
    BTW I have a feeling that in the condition above p != null does not need to be there, because p instanceof Number would return false if p is null. Am I correct? :-)
  • Can I have another question? Is it still needed to count with the fact that settings properties of type Number can be returned as Strings on Android?

    But if it can still be returned as string, than it is far from satisfactory of course...
    BTW I have a feeling that in the condition above p != null does not need to be there, because p instanceof Number would return false if p is null. Am I correct? :-)


    While I've not tested for it in a while, I'd leave the check for it in the code. You may also want to look for "instanceof Float", as I've seen that in Android not long ago.

    In the case of "instanceof String" or "instanceof Float", I just do a toNumber() on it and use it, and that seems to work fine. (all my settings with numbers right now are values between 0 and 100 or so, so no problems with the float versions)
  • I posted some code here that can be used to work around all of the GCM bugs in a central location. It should eliminate lots of duplicated code so when you decide to remove the fix it can be done in just one place.

    Travis