A constructor is invoked twice, how does it happen?

Hi, I met another problem just now.

My code is below.

---------------------app----------------------

using Toybox.Application;
using Toybox.WatchUi;

//golbal variable
class MyApp extends Application.AppBase {
	var myModel;
	var myDelegate;
    function initialize() {
        AppBase.initialize();
        myModel = new $.MyModel();
        myDelegate = new $.MyDelegate();
    }

    // onStart() is called on application start up
    function onStart(state) {
    }

    // onStop() is called when your application is exiting
    function onStop(state) {
    }

    // Return the initial view of your application here
    function getInitialView() {
        return [ new MyView(), myDelegate ];
    }
}

---------------------model----------------------
class MyModel {

    // Constructor
    function initialize() {
    	System.print("Model's constructor invoked");
        // initialize FIR filter
        var options = {:coefficients => [ -0.0278f, 0.9444f, -0.0278f ], :gain => 0.001f};
        try {
            mFilter = new Math.FirFilter(options);
            mLogger = new SensorLogging.SensorLogger({:enableAccelerometer => true});
            mSession = ActivityRecording.createSession({:name=>"Sport", :sport=>ActivityRecording.SPORT_GENERIC, :sensorLogger => mLogger});
        }catch(e) {
            System.println(e.getErrorMessage());
        }
        
        .......
}

---------------------delegate----------------------

class MyDelegate extends WatchUi.BehaviorDelegate {   
    var myModel;
    function initialize() {
        BehaviorDelegate.initialize();        
    	myModel=Application.getApp().myModel;
    }
    ........
}

---------------------delegate----------------------

class MyView extends WatchUi.View {
    function initialize() {
        View.initialize();
    }
    ........
}

Output is:

Background: Model's constructor invoked

Error: System Error

Details: Cannot create a new session while recording is active

Stack: 

  - initialize() at **/MyModel.mc:52 0x10001d84 

  - initialize() at **/MyApp.mc:10 0x10001998 

Model's constructor invoked

Obviously, the constructor is invoked twice, so weird???? 

Thanks a lot for any help.

  • setLabel/setSubLabel work fine on a real device.  I use them both in may things.

    Yep. I've used setSubLabel too.

    So I'm not sure why it should be logical/obvious that setTitle() would *not* work, especially since we know that setLabel and setSubLabel *do* work.

    And why should it be "natural" that setTitle() would appear to work in the sim, but not the real device?

    IOW, I don't get the logic which states "dynamically changing the title is not expected to work because it's a native view and the sim doesn't reflect reality" but "dynamically changing an item is expected to work fine".

    Unless the logic is "I tried it on the real device and it works / doesn't work". Which is another way of saying "don't bother using a CIQ feature unless you own a real device that supports it."

  • It may not be obvious, but having a device to test on with a function like menu2 or maps doesn't seem unreasonable. The sim isn't a full device emulator, and there are lots of things you won't see in the sim.

    both have been around since CIQ 3.0.0, and that's been a few years.

    I doubt I'd support CIQ2/3 devices if I only had a fr 23x, and same with a CIQ 3.x device if I only had a fr735 .

    And I'm already planning on getting a CIQ 4device when one is announced as there are a bunch of new things coming in CIQ 4

  • Afaik, the cheapest garmin device (945) that supports maps retails at $600 USD. I guess 5X is cheaper now, but it was also $600 when it came out IIRC. It's a lot especially when you compare them to the price of an Apple Watch (especially considering that Apple has always positioned itself as an overpriced luxury brand.)

    I wrote an app to support Stryd before I ever had one. It's my most-reviewed app (although the total downloads are nothing special). Stryd used to recommend it on their support pages, and I've heard they recommend it on FB, too. (Not that I think the app is anything too special -- there's a lot of things which could be better.)

    Was it crazy to write a running power app designed for Stryd without even owning one?

    I've written an app which only runs on devices I don't own (due to the large memory requirements).

    It may not be obvious, but having a device to test on with a function like menu2 or maps doesn't seem unreasonable.

    It's not unreasonable assuming one of your hobbies is collecting Garmin watches.

    As I mentioned before, most runners I know are happy with their 235. Maybe they'll upgrade if it breaks. I wouldn't expect a hobbyist dev to spend more money on Garmin devices than they would be prepared to spend if they just buy Garmins for personal use. I mean, if they are able and willing to, that's fine. Others aren't.

    IOW, I would not buy a new watch just for CIQ.

    Having said that, CIQ 4 is kind of exciting, and I'm waiting for the CIQ 4 devices to come out, too. But it's also because I want a new watch for my personal use.

    I also think it's not unreasonable for devs to expect the implementation on the device to broadly conform to the the behavior in the simulator, and the letter/spirit of the documentation. If there's a mismatch, either the device should change or the documentation/sim should be updated.

    For example, I want to add on-device settings to my data fields, but I'm afraid to, given the fact that I don't own a 3.2 watch. I still don't know whether triggering on-device settings will reset a data field app or not. That piece of knowledge would allow me to determine whether certain use cases are even possible. (Like implementing a data field with an alternate lap viewer mode that's triggered via a menu item.)

  • Testing on a real device is important.

    In the case of maps, I doubt I would release an app that used maps unless I had a device with maps to test on.

    The whole map interface was announced at the 3rd Summit, and it just so happened, the take home device that year was the f5+ (with maps!).  When music was announced, the 645m....