I would like to call an async REST endpoint during system events. Nothing is being returned from the method, the app just needs to call it when the events are fired. I’ve tried a few different approaches, including nil listeners but the call never happens and adb provides no insight. I know this is suggested against, but it still seems that it should be possible as long as I’m not expecting a response?
The code below produces the following output
System event name and type: system applicationExit
AFTER REQUEST ****
I don’t expect the handler to be called, nor do I need for it to, but I would expect the network request to be made since it’s performing the 2nd print statement.
<lua>
– APP STATUS RESPONSE HANDLER
local function handleAppStatusUpdateResponse( event )
print(“INSIDE OF HANDLER ****”)
end
– SYSTEM EVENTS LISTENER
local function onSystemEvent( event )
print( "System event name and type: " … event.name, event.type )
local url = "http://54.###.###.##/api/UserApplicationStatus/updateStatus?userEmail=" … glo.userEmail … “&isRunning=”
if (nil ~= glo.userEmail ) then
if(event.name == “applicationStart” or event.name == “applicationResume”) then
network.request(url … “true”, “GET”, handleAppStatusUpdateResponse )
end
if(event.name == “applicationExit” or event.name == “applicationSuspend”) then
network.request(url … “false”, “GET”, handleAppStatusUpdateResponse )
end
end
print(“AFTER REQUEST ****”)
end
Runtime:addEventListener( “system”, onSystemEvent )
</lua>