View.onUpdate(dc) and other Base Class overrides

Hi,

I've noticed the current project wizard (it may have happened earlier than 1.2.11) is adding the line below to the boiler-plate code on the event onUpdate handler for Apps, Wizards and Complex Data Fields. In fact
View.onUpdate(dc);


This makes complete sense that you're calling the Base Class's onUpdate handler.

I have a couple of questions, as this was never part of the original boiler-plate code, and doesn't appear in the samples or some of my earlier Apps. These may be more directed at the Garmin IQ Team.

My questions are:
- What sort of things are planned for the Base Class to do, i.e. what would be rendered with my code? or is it more expected for dc preparation code?
- Should this the first or last thing on the handler, i.e. should it be called before I update, or after I update?
- As this wasn't in the original template/samples, I am guessing it does nothing at the minute, as it's not causing an impact on my earlier projects?
- How quickly should I start adding this line in to older projects, if it will start doing something important?

Cheers
Chris

PS I've also noticed that you rightly now get a warning if you miss the initialize Base Class calls, which also fall into the same point as onUpdate (that they are now part of the template, but were not previously, including samples).
  • Former Member
    Former Member over 8 years ago
    What sort of things are planned for the Base Class to do, i.e. what would be rendered with my code? or is it more expected for dc preparation code?


    The View.onUpdate() function's primary job is to clear the screen and draw the items within your layout. I don't think it does any dc preparation (although I'd have to check to be sure). If you're not using layouts you wouldn't necessarily need to call it.

    Should this the first or last thing on the handler, i.e. should it be called before I update, or after I update?


    Like mentioned above, it will clear the screen. This means if you call it later in your own onUpdate function anything you've already drawn will be wiped out. It also draws the items in your layout. So the proper way to use it would be:
    function onUpdate(dc) {
    // Update items in your layout

    // Call parent onUpdate() to clear the screen/draw the updated layout items
    View.onUpdate(dc);

    // Do any manual drawing here. It will draw on top of the layout.
    }


    As this wasn't in the original template/samples, I am guessing it does nothing at the minute, as it's not causing an impact on my earlier projects?


    The templates added a call because the templates were updated to use layouts. If your project doesn't use layouts you won't notice a difference.

    How quickly should I start adding this line in to older projects, if it will start doing something important?


    If you're going to use layouts I'd recommend adding it. You can manually call draw() on all the items in your layout but why do the extra work? ;) Of course, if you don't - and have no plans to - use layouts then you realistically don't need to call it but it wouldn't be a bad idea to call it anyways.
  • Thanks Ken, excellent response and answer.