Low Memory error on Bangle JS 2

Posted on
  • Hello,
    I am trying to make an app with multiple clock faces and implement functionalities using touch.
    I am uploading the images in this post for your reference.
    I just wish to implement a simple activity; the image with all the activities would lead me to an individual activity when I touch the screen, and then one more tap should lead me to the timer.
    I tried implementing it by putting the code for the timer in the if-else condition. For the simplicity of understanding, I am not posting the entire code here but am replacing them with function names.

    function selectOnTouch(n, event) { 
    if(event.y<60){ walking();}
    else if(event.y>=60 && event.y<120){jogging();}
    else{cycling();}
    

    If I make another function of touch inside some function, like Walking, it gives me a Low Memory error.
    For Eg,

    function selectOnTouch(n, event) { 
    if(event.y<60){ walking(){function selectOnTouchTimer(n, event1) {timer();};}
    else if(event.y>=60 && event.y<120){jogging();}
    else{cycling();}
    

    Could someone point out the mistake/suggest to me how I should change my code? Is there another way I could implement this ?

    Thank you in Advance!
    Pranjal


    5 Attachments

    • Cycling (1).jpeg
    • Jogging (1).jpeg
    • Walking (1).jpeg
    • Screenshot 2022-06-19 152404.jpg
    • Screenshot 2022-06-28 152949.jpg
  • my guess is that it will be some problem with one of the functions like cycling() etc.
    I would suggest swapping out the functions to just print the string 'cycling' etc.
    Also you might want to show the code you are using for the sub functions etc.

  • What happens if you change

    if(event.y<60){ walking(){function selectOnTouchTimer(n, event1) {timer();};}
    

    to

    if(event.y<60){ 
      walking();
      Bangle.removeListener('touch', selectOnTouch);
      {function selectOnTouchTimer(n, event1) {timer();};}
    }
    

    ?

    I'm not sure what line 4 above would actually do though? Seems to me like it's only defining a function - not executing it.

    I would probably try a rewrite to something like

    function selectOnTouchTimer(n, event1) {timer()}
    
    function selectOnTouch(n, event) { 
      if(event.y<60){
        walking()
        Bangle.removeListener('touch', selectOnTouch);
        Bangle.on('touch', selectOnTouchTimer)
      }
      else if(event.y>=60 && event.y<120) {jogging();}
      else {cycling();}
    }
    

    possibly switching line 6 and 7 around.

    Does any of that make it work?

    EDIT: Also, both your examples have too few closing curly brackets. There should be a final one closing out the function selectOnTouch() in both. The second example also needs one more at the end of line 2.

  • Hey @Ganblejs,
    Thank you for your response!
    I realized my error, basically, I draw these walking, jogging, and cycling icons by converting SVG files to Bangle JS. Earlier, I was declaring those in the individual sub-activity screens, so I changed that and I am defining them publicly now.

    I had one small doubt though, is there a way in which I could implement a back button as well?
    Let's say I am going on the walking screen and I select the timer button and that leads me to the timer. Is there a way I could return to the walking screen by clicking some button?
    I read about the [https://banglejs.com/reference#l_Bangle_­setUI] back functionality in the documentation, but once remove the event listener, it doesn't allow me to go back to my previous screen. Is there some way I could implement the back functionality as well?

  • Maybe utilizing setUI would be a good idea to make your app more in line with the overall experience of using the bangle.js, specifically in this case how the back functionality is implemented. But you shouldn't have to if you want to go another route. However, if you get a hang of setUI you'll probably find it useful. :)

    Let's say I am going on the walking screen and I select the timer button and that leads me to the timer. Is there a way I could return to the walking screen by clicking some button?

    In my understanding, going back is for the most part just loading the previous stuff again. So one way to do it could be to have a software button which when pressed loads the walking screen anew. You could also listen for presses to the physical button to trigger a back-function.

    If using setUI there will be an encircled red back button in the upper left corner to press.

    once remove the event listener, it doesn't allow me to go back to my previous screen.

    Would it help to just restart the listener, or start a new separate one, with a Bangle.on('touch' ....) call?

  • Hey @Ganblejs!
    Thank you for the reply. I played around with my code a bit and eventually, SetUI works pretty well!

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

Low Memory error on Bangle JS 2

Posted by Avatar for pranjal @pranjal

Actions