[Watchface] When is the constructor been called?

Hi,

I am a little bit confused when the constructor of a watchface is called. I personally thought, that the constructor is called, if I change settings in GCM or GE. But it is not. Instead it seems that the constructor is called every time I switch back from another screen to the watchface. Is there any documentation about this? Furthermore I am not sure when onShow() is called and when onExitSleep() is called. This is very confusing :-(
  • The life cycles of the classes making up a watchface are pretty simple...

    When the user switches to the watchface, a new App instance is allocated by the system. That object is initialized, onStart is called, and then getInitialView. Typically, you would allocate an instance of the view inside getInitialView, so the view class initialize method would be called then. After that, the view would be prepared by calling onLayout. Once the view was ready to be shown, onShow would be called. Once the view is shown, it is updated via calls to onUpdate. When a watchface is hidden, the app is totally unloaded. (App.onStop is called and the app object is unloaded). The onHide function is not called for watch faces, so I would only expect onShow to be called once for a given instance.

    The onEnterSleep function is called any time the device goes into low-power mode, and onExitSleep is called when leaving low-power mode. Reasons for these transitions can vary by device and by device configuration.

    Travis
  • Hi Travis,

    thanks for clearing things up. This is what I have also observed and make sense. Nevertheless, I am wondering how I am able to store data globally. What I mean is, let's say, I use getGoalView() to detect whether the floors climbed goal was reached. I want to remember to this event even if the watchface is completely unloaded. I could us the object store, but probably there are better ways. In the programmers guide, I found that:

    class AppBase
    {
    // Before the initial WatchUi.View is retrieved, onStart() is called.
    // This is where app level settings can be initialized or retrieved from
    // the object store before the initial View is created.
    function onStart(state);
    }


    What are app level settings and can I use it to store data globally?
  • This is talking about the object store. It even uses the words the object store immediately after your underlined text.

    If you want to persist data that outlives the current execution of your application, you want to use the object store (AppBase.getProperty() and AppBase.setProperty()). This is how you save/restore application data.

    Travis