onUpdate is called twice

I observed that `onUpdate` is called twice in my views. I don't understand why and the solutions I could come up with are

  1. have a switch that remember if it was already called see https://github.com/individual-it/BatteryGuesstimate/pull/4
  2. have a global `_dc as Dc` that is set from `onLayout()` and do the whole drawing in `onShow()`

but both does not sound right.

Any other solutions, or even maybe an explanation why `onUpdate()` is called twice?

  • by the way, I'm doing this in delegate.mc

    Storage.setValue("isReSession", "yes");

    and then on my OnUpdate() that refresh every 30s as you teach me, and it's working

    if (Storage.getValue("isReSession") == "yes") {
    but this condition is always false...
    I println Storage.getValue("isReSession") and print yes, but... I need to convert to string ??
    thanks!
  • 1. "yes" is the string - so you have use equals()

    2. you can put boolean Storage.setValue("isReSession", true); and use if (Storage.getValue("isReSession"))

    3. but you shouldn't use storage every 30s!!! It kills battery.

    In delegate

    - glbIsReSession = true

    - Storage.setValue("isReSession", glbIsReSession);

    In update

    - if(glbIsReSession)

    in app.onStart

    glbIsReSession= Storage.getValue("isReSession");

  • Many thanks!! I already tried the equals like this: 

    if (Storage.getValue("isReSession").equals("yes")) { but gives me error... doesn't matter, your options is better!
    Thanks!
  • Probably errors because there is no value in storage then it return null and error null.equals().

    But it's nice that if(null) == if(false) == if(0).

    But if glbIsReSession is only important for one running app session you shouldn't save anything in storage because when app will start again it will read glbIsReSession! So rather it should be in onStart glbIsReSession = false or do nothing every members/globals is null on the beginning.

  • you really shouldn't be doing a getValue on something more than one time when your app runs.  It hits the vile systm each time.

    The quick what to handle this is with a global in your app where you can that you can change it in the delegate and use in onUpdate()   You only really need to use Storage for things you want to carry over between runs.

  • Thanks to both.

    let me see if I understood.

    app.mc
    ... 
    ...
    
    class teste4App extends Application.AppBase {
    
    public var globalIsRecSession as Boolean;
    
    function onStart(state as Dictionary?) as Void {
    
            globalIsRecSession = Storage.getValue("isReSession"); 
    
    
        }
        
        ....
        ....
    }
    
    delegate.mc
    ...
    ...
    
    class teste4Delegate extends WatchUi.BehaviorDelegate {
    ...
    ...
    var globalIsRecSession = true;
        function onSelect() as Boolean {
        
            if (....) { Storage.setValue("isReSession", globalIsRecSession);
            } ...
        }
    }
    
    view.mc
    
    ...
    ...
    class teste4View extends WatchUi.View {
    
        function onUpdate(dc as Dc) as Void {
        
                System.println("onUpdate " + globalIsRecSession);
        
            }
    }
    
    
    Error: Symbol Not Found Error
    Details: Could not find symbol 'globalIsRecSession'
    Stack: 

    give that error. or should I do

    view.mc 

    class...

    globalIsRecSession = Storage.getValue("isReSession");
    function onUpdate()
    prinln globalIsRecSession 
    ??
  • I'm doing a windsurf app, and I have a menu2 with multiple options of boards, sails and fins, and I want to save it each session.

    before each session I select have "stuff" I will ride.. and I want to "store" the equipment used in each session and another things, like how long as the session, how many jibes, heart rate and "tracking" the session to see on my smartphone.

    what do you think is the best way to do that? to save the information ?

  • 1. globalIsRecSession has to be declared outside any class!

    2. Do you want "to be" in recSession when you start app again????

  • ok, I just need on app.mc

    public var globalIsRecSession = Storage.getValue("isReSession");

    class teste4App extends Application.AppBase {
    .....
    ok, I thing I'm confusing something..
    Storage.setValue... will store the value for every??
    because on my onStop I have 
    Storage.clearValues();
  • not for every but for your app

    if you have clearValues it means you don't need setValue