Venu2 Glance and onTemporalEvent

I was under the impression that when onTemporalEvent ends with Background.exit(), that a call to onBackgroundData would be made, but from what I can see, this only happens if the GlanceView is showing as can be seen by the log below. At 22:57, 23:02 and 23:07, the call to onTemporalEvent, ended with a call to Background.exit() but no onBackgroundData function was called until 23:08 which is when I switched to the Glance view. Plus you can see that data was stuck in the buffer until onBackgroundData was called. Is this normal behavior or is there a way to force a onBackgroundData even when the glance view isn't showing (the whole app class is still loaded so there's no reason to not be able to call it)?

If it's its normal behavior, is there a way to simulate this in the simulator? I couldn't find one and it's hard to debug/work around this through a physical device.

22:57:23 : App: Initialising app
22:57:23 : App: starting app
22:57:23 : App: getServiceDelegate
22:57:23 : ServiceDelegate: onTemporalEvent
22:57:23 : ServiceDelegate : onTemporalEvent getting data
22:57:24 : onReceiveVehicleData already has background data! -> '{status=>408|67|Complete|168|19.400000|false|false| @ 22:52|, responseCode=>408}'
22:57:24 : onReceiveVehicleData: responseCode = 408
22:57:24 : onReceiveVehicleData exiting with data={status=>408|67|Complete|168|19.400000|false|false| @ 22:57|, responseCode=>408}
22:57:24 : App: stopping app
23:02:23 : App: Initialising app
23:02:23 : App: starting app
23:02:23 : App: getServiceDelegate
23:02:23 : ServiceDelegate: onTemporalEvent
23:02:23 : ServiceDelegate : onTemporalEvent getting data
23:02:24 : onReceiveVehicleData already has background data! -> '{status=>408|67|Complete|168|19.400000|false|false| @ 22:57|, responseCode=>408}'
23:02:24 : onReceiveVehicleData: responseCode = 408
23:02:24 : onReceiveVehicleData exiting with data={status=>408|67|Complete|168|19.400000|false|false| @ 23:02|, responseCode=>408}
23:02:24 : App: stopping app
23:07:23 : App: Initialising app
23:07:23 : App: starting app
23:07:23 : App: getServiceDelegate
23:07:23 : ServiceDelegate: onTemporalEvent
23:07:23 : ServiceDelegate : onTemporalEvent getting data
23:07:25 : onReceiveVehicleData already has background data! -> '{status=>408|67|Complete|168|19.400000|false|false| @ 23:02|, responseCode=>408}'
23:07:25 : onReceiveVehicleData: responseCode = 408
23:07:25 : onReceiveVehicleData exiting with data={status=>408|67|Complete|168|19.400000|false|false| @ 23:07|, responseCode=>408}
23:07:25 : App: stopping app
23:08:38 : App: Initialising app
23:08:38 : App: starting app
23:08:38 : App: onBackgroundData
23:08:38 : App: onBackgroundData: 408|67|Complete|168|19.400000|false|false| @ 23:07|
23:08:38 : App: onBackgroundData responseCode is 408
23:08:38 : ServiceDelegate:testAwake
23:08:38 : Glance: Starting glance view
23:08:39 : onReceiveVehicles: 200
23:08:42 : App: stopping app

Thanks.

  • Sound normal to me.  Let's say you have a temporal event that runs every 5 minutes that does a Background.exit(). but your main widget/glance isn't running.  onBackgroundData doesn't get called as that's part of the main app/glance view and does not run in the background.

    As soon as the glance or main view starts, onBackground Data get's called and you see the data from the last time Background.exit() was called

    You can use getBackroundData in the background service to add to what's already queued up frp, Background.exit()

  • Ok thanks. My issue is in this instance, if the makeWebRequest fails with some specific error (401 and 408), it needs to refresh its access token (401) or check if the vehicle is really asleep (408). Waiting for the glance view to run, then you only get that 401 or 408 and need to wait before a call to refresh the token then a call to get the vehicle data, which sucks because the glance viewing isn't showing the data it's supposed to show "at a glance" but after some time.

    i 'fixed' it by piggybacking a call to get data after a call to refresh the token after the last getvehicledata call failed with 401 is returned to onBackgroundData. This has to happen in the foreground code since the token is stored in the app property and a background process can't modify these (being 600+ bytes, it could be quite large to pass between background and foreground through the buffer). That's why I also asked if there is a way to simulate this behavior (ie, no main or glance view running). Is there a way?