GA and suspend/resume events

Hello!

I have encountered what I would qualify as a bug, but I just want to check if it is not a design decision or constraint first.

I try to log an event during the system suspend event.

local function onSystemEvent( event ) if("applicationSuspend" == event.type) then GA.newEvent( "design", { event\_id = "system:suspend"}) suspendApp() elseif("applicationResume" == event.type) then GA.newEvent( "design", { event\_id = "system:resume"}) resumeApp() end end Runtime:addEventListener( "system", onSystemEvent )

Where suspendApp() and resumeApp() are custom functions (calculating the duration of the app suspension, essentially).

When the application suspends, all the code in the custom functions is called, and any print is logged into the console. But not the GA event. In fact, the “system:suspend” event is sent (and logged into the console) only on application resume.

GA: Submitting custom event(s): 'design': { event\_id='system:suspend' } - Server response: {"status":"ok"} GA: Submitting custom event(s): 'design': { event\_id='system:resume' } - Server response: {"status":"ok"}

Is it a bug?

I also sometimes have the suspend event fired twice, but that is another matter.

Thanks

Hi

 

The app will block the network calls when it is being suspended.

 

That is why your system:suspend event isn’t being sent ( and logged in the console ) until it is resumed again.

 

If you want to log the time the app was suspended you could simply do something like this:

 

 

local suspendTime local function onSystemEvent( event )     if("applicationSuspend" == event.type) then         suspendTime = os.time()     elseif("applicationResume" == event.type) then         GA.newEvent( "design", { event\_id = "system:resume", value=os.time()-suspendTime })     end end Runtime:addEventListener( "system", onSystemEvent )

I suspected something like this, but thought the actual suspension took effect after the Corona applicationSuspend (meaning stuff could be done before the app suspends for real).

Anyway, thanks for the answer, and the good workaround

Hi

 

The app will block the network calls when it is being suspended.

 

That is why your system:suspend event isn’t being sent ( and logged in the console ) until it is resumed again.

 

If you want to log the time the app was suspended you could simply do something like this:

 

 

local suspendTime local function onSystemEvent( event )     if("applicationSuspend" == event.type) then         suspendTime = os.time()     elseif("applicationResume" == event.type) then         GA.newEvent( "design", { event\_id = "system:resume", value=os.time()-suspendTime })     end end Runtime:addEventListener( "system", onSystemEvent )

I suspected something like this, but thought the actual suspension took effect after the Corona applicationSuspend (meaning stuff could be done before the app suspends for real).

Anyway, thanks for the answer, and the good workaround