When does onStop() get called for a Watchface?

Is it always called when a watchface gets covered by something? Like a new notification comes in, user goes into a menu, start a new app/activity, etc.
If not, where should thedeleteTemporalEvent be called from when a watchface is not displayed anymore?
  • onStop() is called when the WF exits, not for things like a notification, etc. So for things like moving to a widget or an app. But with backgrounding, it's also called when the background exits.

    So, in onStop() you need to know if it's the background process or the (in this case) watchface. Here's the trick I use to do that:

    create a global like:
    var inBackground=false;

    Then, in the ServiceDelegate, set that to be true:
    inBackground=true;

    in onStop(), then check that variable:
    function onStop(state) {
    if(!inBackground) {
    //you are in the main process and not the background
    }
    }
  • Thanks for the reply, but I need the exact/every cases when the onStop() is called and/or not called.
    I could not find anything related to this in the documentation. Please point me there if it exitsts, else It's needed to be documented if and when for example a notification comes the onStop() is not called, or the user goes into a menu it is not called, etc...
  • If you want to check for yourself, put in a println, and run on the watch with a log file (maybe include a timestamp so you can keep track of when). It's also noted if it's run by the background when logging on the watch.

    When you go to the widgets, it will be called. When you start an activity, it will be called. Menus, it will, and if the watch previews WFs, it will be called when you switch to a different preview. Notification don't as far as I've seen, as it's just a new view on top of the WF and doesn't stop the WF.