Background notifications stop ongoing activity

I've been notified by a User that my widget's Temporal notifications are:
1. Triggered when he has the option set to "not receive notifications during the activity".
2. When interacting with the notification, the activity is lost.

My question is: Do I have to programatically check that notifications are disabled and/or an activity is in progress in my background code? And if so, what is the best way to test in the simulator?
- This would be inconsistent with the "do-not-disturb"/"sleep" mode, which disables the Temporal event from triggering.

Hope someone can help shed some light into this matter. Thanks!


  • What device?  

    Having notifications on/off really shouldn't make any difference.  The background runs if it can run.

  • Hi Jim,

    The device is a FR935.

    For context, the feedback I got was:
    "Good afternoon. During my running activity today, I received a notification from the widget that my 16 hours of fasting have been reached. Afterwards I found myself on my home screen. If my activity was finished or not, I didn't know that and have to deal with what was really bad while running."

    He further clarified that:
    "I wondered that this notification comes during my activity because I disabled notifications during activities."

    As I said, I know that the notifications (pushed by the BG logic) are not triggered during "sleep/do-not-disturb" in my test device which is a Venu. I also never ran into this situation myself, that is why I ask if someone can give me hints on how to test it in the simulator.

    I got as far as checking for the "activity info" in the background code, so I don't push the notification when its ongoing. 
    From the docs: "The current Activity Info or null if there is no current activity."

    That said, I never get "null" in the simulator, which is strange since I never started an activity (couldn't even find an explicit way to do it). But this is not too important as I can check e.g. the elapsed time field.

    What I would like to know is, if the User has notifications during activities disabled, shouldn't the system prevent them from bubbling up (like in "do-not-disturb"/"sleep" mode), or is the Connect IQ developer that needs to check settings and act accordingly?



  • Oh, ok, it was requestApplicationWake() and not just a notification (like an email just came in).

    There's not enough memory for the full widget to run if the user says "yes", so the activity gets shut down.  You'll see the same thing if you go to the widget loop in an activity and try to run a CIQ widget, but there it warns you.

    I'm not sure how you can tell in a background if the background is running during an activity.

  • That makes sense.

    I'll try something like this to prevent the widget from being woken during an activity:

    // Check if an activity is running
    // We cannot wake the app when an activity running else
    // the user's activity can be lost due to lack of memory
    var activityInfo = Toybox.Activity.getActivityInfo();
    if (activityInfo != null and activityInfo.elapsedTime > 0) {
        Background.exit(true);
        
        return true;
    }


    Maybe it's also possible to setup a "new" temporal event, for e.g. the next relevant milestone when running in the BG?
    I thought I read somewhere that this is not possible, worth a try though.

    Thanks for the hints!

  • For future reference, this approach works in the simulator.

    1. Exit the widget (go "Back" in the simulator), this registers the Temporal event timer.
    2. Push a Temporal event via the Simulator (a wake dialog is show for the correct state) ⇨ Accept (wakes widget)
    3. Exit the widget again.
    4. Start an activity: Data Fields ⇨Timer  Start Activity
    5. Push another Temporal event via the Simulator, this time the code detects ongoing activity and exits.

    Caveat: Notification is lost, and no further notifications will be shown until the user visits the widget again!

    TODO: Test is a timer can be set for a later milestone in the BG logic (very likely not possible).