• Apologies this may have come up before but I could not find it in the search.
    Is it safe to register a listenner more than once ?
    Is there a way to find out if I have already regsitered a listenner ?

    How this arises. I have an app that can turn the GPS on / off. I also have a control that can switch on the logger without having to exit the App, switch it on and then reneter my App. If the Apps starts with the GPS off, I may power it on and then switch on the logger. If the Apps starts and I switch on the logger then this will effectively power on the GPS and I want to register a listener at that point as well.

    BTW could not find documentation for Bangle.on() in the API reference ? Am I missing something.

  • In Espruino, on is part of every object, so you can find the docs at http://www.espruino.com/Reference#l_Obje­ct_on

    Calling on twice is no problem, but then you end up with both functions getting called. You can use .removeListener or .removeAllListeners to get rid of old ones (I'd recommend not using removeAllListeners as it may interfere with widgets that had registered their own handlers).

    Examples of use are at that link above

  • Ah, a very basic question fitting here which I wanted to ask since two years: What happens to event listeners and set intervals on Bangle.js, when the app is changed to another one (and therefore quit)? I suppose all listeners and intervals are cleaned up. Is this right?

  • If I have more than one place in the code where I need to add the exact same listenner then I found I had to keep a count so I knew I did not execute the same registration again. Otherwise I found the callback did not get called or I could not see the callback being called.

  • I would not count it, but store it in a global variable and then check it.

  • @HughB I guess this is mainly for the 'Kitchen' app? Just a thought but your original motivation was to avoid turning GPS off/resetting compass? Since 2v10 or so that hasn't been an issue (GPS is kept on for ~1 sec even when new apps are loaded, in case they ask for it again) so if you're finding you are fighting the system might it be worth looking at revisiting using separate apps?

    What happens to event listeners and set intervals on Bangle.js, when the app is changed to another one (and therefore quit)? I suppose all listeners and intervals are cleaned up. Is this right?

    Yes - Bangle.js actually cleans everything up - which is a cause of frustration to some users, but it does make things a lot easier and more reliable. You know when you start a new app it's always going to start in the same state, and not run out of memory because of any app you'd run previously :)

  • I guess this is mainly for the 'Kitchen' app?

    It was a general question though it does apply to Kitchen Combo.

    The original motivations for kitchen combo were:

    • ability to switch to another App without the GPS turning off and having to go through first fix
    • ability to share the GPS fix between apps quickly
    • speed in terms of switching between apps
    • avoidance of having to navigative through the launcher to another app

    I agree that 2v10 solves about half of these issues. Bangle.isGPSOn() and Bangle.setGPSPower(1,'mytag') have improved things enormously. When the new JIT to assembler code project is done I would guess that apps will load superfast without any delays when you switch to start the launcher and select an app.

    so if you're finding you are fighting the system.

    Kitchen combo was not so much fighting the system but pushing things to the limits of what could be done at the time. I'm going down the route of seperate apps on Bangle 2. No plans to port Kitchen Combo to Bangle 2. I have built GPS Touch for Bangle 2 which is effectively a replacement for Walkersclock - but a lot cleaner in the code and easier to use.

  • So I guess the main thing that's now available yet is the fast app switching?

    I'm hoping that with the swipe gestures you'll be able to have right->gps touch and so on, so then it's really quick to swap apps. The actual app load speed should be pretty reasonable now - hopefully under half a second.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

is it safe to register a listenner twice ? EG Bangle.on('GPS', processFix)

Posted by Avatar for HughB @HughB

Actions