Glance view active + background job

Former Member
Former Member

Hi,

Is it only simulator? Or also real device?

I have a widget with glance view. Widget is periodically calling a background job to grab data. Once for couple of hours.

As we know - glance view has very limited memory (~28kB)

When having glance view active - and simulating background event - I have realised that -

- Background event is fired correctly in a separate memory - at least according to simulator

- onBackgroundData event is fired in context of glance view - therefore with above memory limitation (~28kB) - causing immediately in my case out of memory error (or to be precise - error without any message, yet by limiting amount of returned data just to one byte - finally I got error message, not only crash)

My question is - is onBackgroundData on real device also called (while in Glance View) in same memory context as GlanceView?

If so - definitely I have suspend background job - as it doesn't make sense... not sure how. Otherwise I can ignore that - as (at least in my case) it may happen very rarely, yet don't like such approach.

Different solution - to check available memory in 'onBacgrdoundData' and eventually skip processing data - if not enough memory.

  • Hi,

    I'm seeing the same issue in the simulator AND definitely also on the device (fr945)!

    The onBackgroundData() is executed in the GlanceVIew instance rather than the main instance.
    For me, that also doesn't make sense as all the processing of the data from BG happens in the main app.

    until this is fixed (doesn't look likely based on this thread having been unanswered for 2 years now) the BG<->MainApp communication is basically broken and can only be achieved via Storage.

  • What you are seeing is normal.  onBackgroundData will be called in both the glance as well as the main app.  If it's called in the glance, I put it in storage so the main app can also see it, and v/v where the main app will put it in storage so the glance can access it.  While I'll read storage/settings in a background, I don't ever write anything to storage/settings in the background service.  It works fine.

    Having onBackgroundData when in a glance actually makes a lot of sense.  For example, I have a widget that uses a background service that gets weather data on a regular basis.  If the background runs while in the glance/widget loop, I can update the glance (if "live update" is true for the device!).  I don't consider it a bug at all, but something you need to handle.

    I have a number of things with a background service and a glance, some that just do everything local to the watch (track the battery level for example), and some that do a makeWebRequest for things like weather.  And others with no background service, but use BluetoothLowEnergy in both the glance and main app.

    The way the prg is built, things with the background annotation come first.  This is so that when the background runs, only the first part of the prg gets loaded into memory.  Next comes things with the glance annotation.  So when the prg gets loaded for a glance, the first two chunks of the prg get loaded.  And in the case of the main app, the entire prg is used (so the background and glance view code also gets loaded as well as the code just for the main app.)

    One thing to keep in mind is that while the background is limited to 28k on some devices, if you have a glance, that's also got the same limit, but that's the glance plus the code for the background.

    Yes, this all can be a bit tricky but it's the way things work.

  • Hi, some devices like the Forerunner 245 Music have 64 KB for Background but just 32 KB for Glance. How does that work in relation to what was stated above?

  • Hi, i am investigating an issue with a bg web request and trying to write the retrieved data to storage in order for the glance to use it. Can you explain the comment re: live update?

    how would I check that is on or off t/f per device. Not worth allowing the bg task of the device can’t use it 

  • See https://developer.garmin.com/connect-iq/core-topics/glances/#glances

    "Live UI Updates" and "Background UI Updates"

    In both cases. onBackground data is called as expected, but with Background UI Updates, you can't just do a WatchUi.requestUpdate() to update the glance when that happens

    "Devices that have less memory [2] will start the app only when the system deems it appropriate, and calls to WatchUi.requestUpdate() will have no effect"

    There isn't a way to see if they are live or background at runtime.

    Most of the watches, the glance view will will time out in a couple minutes if there is no user interaction and return to the watch face.