leaving an app and coming back to it: what should my app do?

I was experimenting with something using my app. During the test I intentionally left the app by long clicking the back button (physical fr965 FW 27.09) to go to the watch face, then looked at some widgets, and then came back to the app 30 seconds later. And then I continued my walk (which wasn't part of the test, it's just my usual daily walk, which I was doing while testing) and about 20 minutes later I suddenly looked at the screen and noticed that the distance is odd.

It should've passed 2km by now, and it's 1.39km. I continued walking abut it was clear that the distance is not changing. I did some things (left the app again and came back, which obviously didn't fix it), then I changed the GPS settings (I was in an indoors walk, which by default is without GPS, but because this is in my app and not the Walk Indoors activity I was able to change the GPS setting), and then went out for a few minutes, and there it was, the distance was increasing again.

A bit later I saved the activity and looked at it's graphs in Garmin Connect. And just as I already was expecting there was a huge 20 minute gap, that started at the time I first left the app to the watch face, and ended when I turned the GPS on. Between these times the pace is missing, the cadence in 0 and interestingly the temperature is also missing (except in 2 spikes where seems to be a few seconds of data *) but there HR (from the optical sensor of the watch) is there for the whole time.

*) Il add that I have been walking in my saloon, without my Tempe, which was all of the time in another room, so I don't really know whether it was connected to it or not, but still it seems that at the same time the cadence stopped the temperature data also stopped.

Interestingly one thing I started to suspect yesterday came from this sentence of the documentation: https://developer.garmin.com/connect-iq/api-docs/Toybox/Position.html#enableLocationEvents-instance_function

Note:

Multitasking: Location events will be disabled when app enters inacitve state, and re-enabled when is active again. These state changes are denoted by calls to AppBase.onActive() and AppBase.onInactive().

Invoked when app enters inactive mode, i.e. hidden by system and not occupying screen. Access to certain system resources will be limited, such as GPS, ANT, Alerts (Vibs tones, flashlight).

Invoked when app enters active mode, i.e. occupying screen in the foreground.

So I wonder whether "and re-enabled when is active again" is really happening. I got reports from numerous users telling me that their map stopped mid hike or that their distance is much less than supposed to be. Until now I investigated in a totally different direction (thought that there is a bug in the way I disable/enable location to save battery when the user stopped the activity for more than a minute [because there's no way to do "Resume later" in a watch-app]) but now I start to think that the issue may be with some of the above 3 citations.
Can you help me
a) understand the docs
b) point at where I could improve my code (I don't have onActive, onInactive implemented at the moment)
b.2) should I also check for similar issues in datafields?
c) tell me about your experience with situations like my users experience
d) if it's a bug either in the firmware or the documentation then what should I write in a bug report?

Top Replies

All Replies

  • And a few minutes after I posted this I started the app again, disabled the GPS, started an Indoors Walk activity, and walked a few more minutes doing another test for the "leave the app, wait 30 seconds, come back to the app" and then walked a few more minutes. However this time even stranger things happened:

    1. after coming back to the app my distance was increasing, but in a strange way *)

    2. after saving the activity I see in Garmin connect that the cadence went to 0 again and kept being 0 until the end of the activity

    3. my pace was strange (gaps every couple of seconds even though I was walking around the saloon non-stop in a steady pace)

    4. and this was the clue: there is a map!

    *) So in hindsight I think what happened is this:

    Somehow (probably the previous test that I wrote about above) left the DEVICE (not the app) in a state that the GPS is on. Even though when I started the app 15 minutes later I explicitly turned off GPS (and I see this in the logs as well, I now for 100% certainty that the app called:

    Position.enableLocationEvents(Position.LOCATION_DISABLE, null);
    and it never called Position.enableLocationEvents with any other parameters, yet there was a GPS signal (funnily enough my app even logs the signal strength to fit file). This explains why I had some pace and distance while circling in my saloon between the windows on the 2 sides.
    So my current guess is that there's some firmware bug on fr965 27.09 (and if I extrapolate this to other user's reports that are coming for months from different devices, than probably this is a wide spread bug) that keeps the GPS on, even when then app explicitly turns it off.
    This would explain why some people have battery drain issues even when the app turns everything off (see:  Battery drain after app exit caused by ActivityRecording API and  Battery drain when ConnectIQ app is not running  and maybe also  Increased Battery Consumption with Positioning Enabled in Manifest  and probably also  Does System.exit() close ActivityRecordings and GPS? )
    If I think further, then my guess is that leaving the app it somehow enters this strange limbo state, and then it somehow forgets which things were enabled by the app, and when the user returns to the app, then even when it explicitly disables location, it only "disables" it in the "app level", but keeps it enabled in the "device level" thinking it was enabled by something else ("because it was on when the user entered the app again").
  •     I think following on the original post and my 1st comment here you should be able to reproduce this on a fr965 with FW 27.09 using my beta app: https://apps.garmin.com/apps/ef804c1d-1757-40b8-acb9-78657395f8cd (use version 58) Let me know if you need more precise steps to reproduce it.

  • Interestingly one thing I started to suspect yesterday came from this sentence of the documentation: https://developer.garmin.com/connect-iq/api-docs/Toybox/Position.html#enableLocationEvents-instance_function

    Note:

    Multitasking: Location events will be disabled when app enters inacitve state, and re-enabled when is active again. These state changes are denoted by calls to AppBase.onActive() and AppBase.onInactive().

    Invoked when app enters inactive mode, i.e. hidden by system and not occupying screen. Access to certain system resources will be limited, such as GPS, ANT, Alerts (Vibs tones, flashlight).

    Invoked when app enters active mode, i.e. occupying screen in the foreground.

    Just my 2 cents, but I could've sworn that this "multitasking" CIQ stuff is only for devices which have a task switcher (like Fenix 7/7 Pro/8, maybe certain newer Venu/Vivoactive devices, maybe FR570/FR970, but not FR955 and not - as far as I know - FR965 (which is very similar to FR955 except for all the AMOLED things).

    Meaning that I could be wrong, but I don't think your real device ever calls onActive or onInactive.

    I think one way to know if a watch has a "task switcher" is to look in the overview/intro section of the manual. For devices that have a task switcher, the manual will describe some button shortcut or gesture that shows a list of recently used apps (which is the task switcher itself, I guess).

    [1/2]

  • Fenix 7 Manual

    https://www8.garmin.com/manuals/webhelp/GUID-C001C335-A8EC-4A41-AB0E-BAC434259F92/EN-US/GUID-85E597B6-976C-4E1D-AE29-0EBBDDD4613C.html

    Fenix 8 Manual

    www8.garmin.com/.../GUID-9CF7D6B1-E02C-4C67-B45E-F0ABDCC2180A.html

    I noticed that neither the FR955 nor FR965 manuals mention being able to view a list of your recently used apps (and ofc I know from personal experience that FR955 has no such feature).

    Ironically, some Fenix 7 users have complained that CIQ device apps stop recording (and/or exit completely) if you return to the watchface (or something like that), which is not an issue for Fenix 6 / 6 Pro or for Forerunners of a similar generation as Fenix 7.

    In other words, from one POV, having a task switcher on your watch results in less functionality than watches which don't have a task switcher.

    (Kinda interesting that Garmin recently started "officially" referring to the buttons by their position, like lower-right, instead of their function, like BACK/LAP. While I absolutely understand why - lots of users seem to have no idea what most of the buttons do, and they especially don't know how to open a menu - it's also kind of awkward to completely divorce the "standard" button names from their function.)

    [2/2]

  • Ofc I am not saying that devices without a task switcher have no way to switch from a CIQ device app or native activity to the watchface or a glance. I'm just saying that they don't have "multitasking" as described in the docs that were linked, especially the part about the app lifecycle (pertaining to multitasking) and the various multitasking callbacks (like onActive/onInactive).

  • Yes, I also noticed that according to the docs fr965 doesn't have onActive, onInactive. So that partially invalidates my original assumptions (and of course even if I'd receive a good advice what to put in onInactive, onActive on newer device won't help to fix it on fr965), but all the experience that I report above from my fr965 is definitely happening and I am able to reproduce it, and so far it looks like the only way to disable the GPS is restarting the watch.