Simulator crashing due to network.request callback after applicationExit

I have a need to make an API call on application exit (to collect session data in an analytics platform). I make a network.request POST when there is an applicationExit system event.

When I’m working in the simulator and save a piece of code the simulator tries to refresh, issues an applicationExit (and fires my POST correctly), then starts re-loading the simulator. It then crashes the simulator. I assume it’s because the network.request is generating a callback to my listener which no longer exists.

It doesn’t seem to be a huge problem on the actual devices, but I wonder what it’s doing in the background and whether it will cause other problems.

Is it possible to issue a network.request POST without including a listener so that it doesn’t try to call me back, or is there a better way to handle this sort of requirement?

Generally speaking making network.request() calls during a suspend or exit operation will be problematic. You can only execute a light amount of code. Anything that takes so much time that it’s implemented with the need of a call back function will simply take too long.

You might be able to make a network.request() and hope the server gets the information before the OS kills your app.

Rob

The server is getting the call just fine, but the Corona simulator is crashing every time I update my code. Is it possible to tell network-request that you don’t want a callback?

Don’t provide a listener function, just pass in nil.

Rob

@beernathan,

Did this solution work for you?

I’ve encountered this before too and ignored it.  I was restarting apps in the middle of ongoing traffic and refreshes.  i.e.Not in a suspend/exit event.  However, if I restarted (the simulator) at just the right time I would hang.  A simple quit + re-run fixed it, but   I’ve always been curious about the source of the hang.

-Ed

Yes! That worked Rob - thanks.

I just passed nil as the listener and it no longer causes a sim crash - that will significantly speed up my build/debug loop!

Nathan.

Generally speaking making network.request() calls during a suspend or exit operation will be problematic. You can only execute a light amount of code. Anything that takes so much time that it’s implemented with the need of a call back function will simply take too long.

You might be able to make a network.request() and hope the server gets the information before the OS kills your app.

Rob

The server is getting the call just fine, but the Corona simulator is crashing every time I update my code. Is it possible to tell network-request that you don’t want a callback?

Don’t provide a listener function, just pass in nil.

Rob

@beernathan,

Did this solution work for you?

I’ve encountered this before too and ignored it.  I was restarting apps in the middle of ongoing traffic and refreshes.  i.e.Not in a suspend/exit event.  However, if I restarted (the simulator) at just the right time I would hang.  A simple quit + re-run fixed it, but   I’ve always been curious about the source of the hang.

-Ed

Yes! That worked Rob - thanks.

I just passed nil as the listener and it no longer causes a sim crash - that will significantly speed up my build/debug loop!

Nathan.