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?

  • I already saw what was my mistake, I wasn't "update" the 

    globalIsRecSession = Storage.getValue("isReSession"); on the delegate.mc
    lets see if I'm doing it the right way:
    
    app.mc
    
    import ..
    ....
    
    
    public var globalIsRecSession = Storage.getValue("isReSession");
    
    class teste4App extends Application.AppBase {
    
    
    delegate.mc
    
    function OnSelect....
     if (....) 
    Storage.setValue("isReSession", true);
    globalIsRecSession = Storage.getValue("isReSession");
    
    view.mc
    
    onUpdate()
    if(globalIsRecSession) is working :D
  • in my opinion should be

    delegate.mc-------------------

     var globalIsRecSession;//default null so do nothing

    function OnSelect....
     if (....)
    globalIsRecSession = true;

    view.mc-----------------------

    onUpdate()
    if(globalIsRecSession)

    it's enough, no storage operation at all because if you start app again you can't use globalIsRecSession from previous app session

  • make sense. thanks ;)

  • very simple case:

    var myVar=false;
    
    class MyView extends WatchUi.View {
    
        //..other stuff
        function onUpdate(dc) {
            //..other stuff
            if(myVar) {
            
            } else {
            
            }
            //..other stuff
        }
        
    }
    
    class MyDelegate extends WatchUi.BehaviorDelegate {
        //..other stuff
    
        function onMenu() {
            myVar=!myVar;
            WatchUi.requestUpdate();
            return true;
        }
    }

    Each time the menu key is pressed. myVar toggles state in the delegate, and is used in onUpdate right away.  No storage involved.

  • ok, without storage do you think onUpdate every second is good or bad for battery? 

  • thanks! in SDK are some example about what I want to do? save information to show on connect iq? thanks!

  • if data can change every second you should draw every second if every hour every hour, you don't need to force drawing (by calling requireUpdate) if you know that data on screen is good (system should call onUpdate when it knows you should redraw screen (e.g. after onShow)

  • Using Storage for this is a bad idea.  No ifs, ands or buts.

  • You are talking about fitContrib which is very different than Storage.