Ticket Created

Super Method Call Not Working

When trying to call a parent method it does not get called.

In the below code the GenericDelegate.initialize() method gets called, but the GenericDelegate.onKey(evt) method does not.

This occurs on SDK 4.2.x and 6.2.x, but not on 4.1.x

class RefWatchInputDelegate extends GenericDelegate {

  function initialize() {
    GenericDelegate.initialize();
  }

  // Handle a keyed input
  function onKey(evt as Ui.KeyEvent) as Boolean {
    if (GenericDelegate.onKey(evt)) {
      return true;
    } else if (evt.getKey() == Ui.KEY_DOWN) {
      return dispDevInfoView();
    } else if (evt.getKey() == Ui.KEY_UP) {
      return dispActivityView();
    }

    return false;
  }
}

class GenericDelegate extends Ui.InputDelegate {

  hidden var escPressTime = 0;

  function initialize() {
    Logging.debug("Generic Delegate initialize()");   
    InputDelegate.initialize();
  }

  function onKey(evt as Ui.KeyEvent) as Boolean {
    Logging.debug("Handling Key Event: " + evt.getKey().toString());

    // If the start key is hit
    if (evt.getKey() == Ui.KEY_ENTER) {
      Logging.debug("Enter Key Pressed");
      sendEvtToApp(evt);
      return true;
    }

    // Handle the escape key. Only works on double press
    if (evt.getKey() == Ui.KEY_ESC) {
      var time = Sys.getTimer();

      Logging.debug("ESC Key Pressed at time: " + time.toString());

      if (time - escPressTime <= func.sec2msec(1)) {
        sendEvtToApp(evt);
        escPressTime = 0;
      } else {
        escPressTime = time;
      }
      return true;
    }

    // Handle the menu key press
    if (evt.getKey() == Ui.KEY_MENU) {
      Logging.debug("Menu Key Pressed");
      return dispMainMenu();
    }

    return false;
  }
}

  • No problem reproducing it with that additional detail. Thanks!

  • Hi ,

    thanks for taking your time to solve this problem, today I was removing code from my watchface project to send you the zip sample as simple as possible, when I detected that after removing almost all the code and resources it started working, so I copied the full project again and started to remove one thing and test, remove other thing and test, after removing almost all I found out what causes the problem.

    In my case, in the class "Parent extends WatchUi.WatchFace", if you define a static var like this for example:

    class Parent extends WatchFace {
          
        // Configuración de la aplicación
        static var PROPERTY_LOAD_CONFIG_FROM_ID = "LoadConfigurationFrom";
    The "onUpdate" on the parent stops being called, if I remove/comment the static var the "onupdate" on the parent is called. I have other watchfaces where I did not have this problem, so I tested to declare a static var on the parent view class and the problem is reproduced.
    Please, declare the static var on the parent and tell me if you reproduce the problem, if you still can't reproduce it I will send you my sample
    Waiting news from you.
    Thanks
  • I've spent about an hour trying to reproduce this issue using both code snippets provided and have failed miserably. Here is my latest test app source code...

    using Toybox.Application;
    using Toybox.Graphics;
    using Toybox.Lang;
    using Toybox.System;
    using Toybox.WatchUi;
    
    class Parent extends WatchUi.WatchFace {
    
      function initialize() {
        // do things
        // it's called
        System.println("Parent.initialize");
        WatchFace.initialize();
      }
    
      function onUpdate(dc) {
        // do things
        // NOT Called
        System.println("Parent.onUpdate");
      }
    }
    
    class Child extends Parent {
    
      function initialize() {
        System.println("Child.initialize");
        Parent.initialize();
      }
    
      function onUpdate(dc) {
        System.println("Child.onUpdate");
        Parent.onUpdate(dc);
      }
    }
    
    class NoBuenoApp extends Application.AppBase {
    
      function initialize() {
        AppBase.initialize();
      }
    
      function getInitialView() {
        return [ new Child() ];
      }
    }

    When I run it, I see the following output.

    Child.initialize
    Parent.initialize
    Child.onUpdate
    Parent.onUpdate
    Child.onUpdate
    Parent.onUpdate
    Child.onUpdate
    Parent.onUpdate
    Child.onUpdate
    Parent.onUpdate
    Child.onUpdate
    ...

    Could one of you generate a .zip of a test project folder that I can use to reproduce the issue and send it to [email protected]? Please put my screen name somewhere in the body of the message so it gets forwarded appropriately. Additionally, please include a copy/paste of the compile line and terminal output generated when compiling the app. If you're using VSCode, this is can be found on the Terminal view (View > Terminal). It should look something like this...

    Executing task in folder NoBueno: D:\jdks\1.8.0_144\bin\java.exe -Xms1g -Dfile.encoding=UTF-8 -Dapple.awt.UIElement=true -jar c:\Users\Vitek\AppData\Roaming\Garmin\ConnectIQ\Sdks\connectiq-sdk-win-6.2.1-2023-06-26-124cb49c5\bin\monkeybrains.jar -o bin\NoBueno.prg -f c:\Users\Vitek\workspace\testing\NoBueno\monkey.jungle -y D:\grmn\prj\di\connectiq\toolchain-3.x\developer_key.der -d fenix7_sim -w -O 2 
    
    WARNING: fenix7: No supported languages are defined. It's a good idea to indicate which languages you are supporting.
    WARNING: fenix7: The launcher icon (30x30) isn't compatible with the specified launcher icon size of the device 'fenix7' (40x40). Image will be scaled to the target size.
    

    Once I have a test case that reproduces the issue, I'll try to figure out what is going on with this.

  • Same problem here, initialize on parent is being called, onUpdate on parent it is not called.

    Fullscreen
    class Parent extends WatchUi.WatchFace {
    
      function initialize() {
        
        // do things
        // it's called
      }
      function onUpdate(dc) {
        // do things
        // NOT Called
      }
    }
    
    class Child extends Parent {
    
      function initialize() {
        Parent.initialize();
      }
      
      function onUpdate(dc) {
        Parent.onUpdate(dc);
      }
    }