On-device settings working on sim but not on the device ?

Hello,

I'm trying to setup basic on-device settings on my 955 watch face, reusing Jim's Menu2 code snippets, as found on the forum :

class watch00App extends Application.AppBase {

    var _temp as Boolean?;

    function initialize() {
        AppBase.initialize();
        _temp = false;
    }

    // onStart() is called on application start up
    function onStart(state as Dictionary?) as Void {
    }

    // onStop() is called when your application is exiting
    function onStop(state as Dictionary?) as Void {
    }

    // Return the initial view of your application here
    function getInitialView() as Array<Views or InputDelegates>? {
        return [ new watch00View() ] as Array<Views or InputDelegates>;
    }

    function getSettingsView() {
        return [new SLeanSettingsMenu(),new SLeanSettingsMenuDelegate()];
    }
}

class SLeanSettingsMenu extends WatchUi.Menu2 {
    function initialize() {
        Menu2.initialize(null);
        Menu2.setTitle("Settings");
		Menu2.addItem(new WatchUi.ToggleMenuItem("Show Seconds When Possible", null,"sec",getApp()._temp, null));
        //other things
    }    
}

class SLeanSettingsMenuDelegate extends WatchUi.Menu2InputDelegate {
    function initialize() {
        Menu2InputDelegate.initialize();
    }

  	function onSelect(item) {
        System.println("onSelect() entered!");
        System.println(item.getId());
  		var id=item.getId();
        if(id.equals("sec")) {
            getApp()._temp = !getApp()._temp;
            System.println(getApp()._temp);
  			// MySettings.showSecs=!MySettings.showSecs;
  			// MySettings.writeKey(MySettings.showSecsKey,MySettings.showSecs);
  		}
  	}
  	
  	function onBack() {
        WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
		return;
    }
}

function getApp() as watch00App {
    return Application.getApp() as watch00App;
}

It works fine on the sim, when triggering the watch face settings, then escaping it...

But on my 955, even if the settings menu appears in the watch face menu, and even if I can select the option, switch the boolean ON/OFF, then come back, the onSelect() function is never entered !?! There's no trace of the println in the log files (all other logs are there though), and the boolean value is never stored/modified.

What could prevent the onSelect() function to be called ? And why is it working on the sim and not on the watch ?

Thanks for your help!

Nicolas.

  • Looks like this is based on code I posted a while back.  You have line 52 commented out.  What that's doing is saving the value to Storage, so next time the app runs, it load the setting from storage.  When you run on a real device, after you change something the watch face is closed, and then will restarted, so unless you save the setting, it will use the default value.

  • what method are you using to save setting, I am using this and does not work, it works until you apply watchface

        public function onSelect(menuItem as MenuItem) as Void {
            var id = menuItem.getId();
            if ((id instanceof Number) && (menuItem instanceof ToggleMenuItem)) {
                Storage.setValue(id as Number, menuItem.isEnabled());
                if(menuItem.getId() == 1){
            	mod1 = Storage.getValue(1);
            	Application.Storage.setValue(1,mod1);
            	}
            	if(menuItem.getId() == 2){
            	mod2 = Storage.getValue(2);
            	Application.Storage.setValue(2,mod2);
            	}
            }
        }

  • Here's something that is working on my watch:

    class watch0bApp extends Application.AppBase {
    
        var _seconds as Boolean?;
    
        function initialize() {
            AppBase.initialize();
        }
    
        // onStart() is called on application start up
        function onStart(state as Dictionary?) as Void {
            // load settings
            _seconds = Application.Storage.getValue("SECONDS_FLAG");
            if (_seconds == null) {
                _seconds = true;
            }
        }
    
        // onStop() is called when your application is exiting
        function onStop(state as Dictionary?) as Void {
        }
    
        // Return the initial view of your application here
        function getInitialView() as Array<Views or InputDelegates>? {
            return [ new watch0bView() ] as Array<Views or InputDelegates>;
        }
    
        function getSettingsView() {
            return [new SLeanSettingsMenu(),new SLeanSettingsMenuDelegate()];
        }
    
        function onSettingsChanged() {
        	// load settings
            _seconds = Application.Storage.getValue("SECONDS_FLAG");
            if (_seconds == null) {
                _seconds = true;
            }
        	WatchUi.requestUpdate();
        }    
    }
    
    class SLeanSettingsMenu extends WatchUi.Menu2 {
        function initialize() {
            Menu2.initialize(null);
            Menu2.setTitle("Settings");
    		Menu2.addItem(new WatchUi.ToggleMenuItem("Show Seconds When Possible", null,"sec",getApp()._seconds, null));
            //other things
        }    
    }
    
    class SLeanSettingsMenuDelegate extends WatchUi.Menu2InputDelegate {
        function initialize() {
            Menu2InputDelegate.initialize();
        }
    
      	function onSelect(item) {
            System.println("onSelect() entered!");
            System.println(item.getId());
      		var id=item.getId();
            if(id.equals("sec")) {
                getApp()._seconds = !getApp()._seconds;
                System.println(getApp()._seconds);
                // load settings
                Application.Storage.setValue("SECONDS_FLAG", getApp()._seconds);
      			// MySettings.showSecs=!MySettings.showSecs;
      			// MySettings.writeKey(MySettings.showSecsKey,MySettings.showSecs);
      		}
      	}
      	
      	function onBack() {
            WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
    		return;
        }
    }
    
    function getApp() as watch0bApp {
        return Application.getApp() as watch0bApp;
    }
  • thanks a lot, think it's because the onSettingsChanged

  • Interesting that this works on the watch, but not in the sim. onSettingsChanged() isn't called in the sim and from a bit of testing I think the watchface may be getting restarted when the settings menu is closed, because I commented out the code in it and it still worked on the watch.

  • onSettingChanged is only called with app-settings from a phone.  Not for on device settings.

    The watch faces gets restarted when you apply the watchface with on device settings.