Best practice GPS location on application suspend and resume

Hi,

In simulator application starts like this

function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. -- resume network call timer trtimer = 65 delayTimer = timer.performWithDelay( 1000, listener, trtimer ) -- Activate location listener Runtime:addEventListener( "location", locationHandler ) Runtime:addEventListener( "system", onSystemEvent ) end end

Location handler is like this

local locationHandler = function( event ) print("GPS Running") in simulator print once -- Check for error (user may have turned off location services) if ( event.errorCode ) then print( "Location error: " .. tostring( event.errorMessage ) ) else local latitudeText = string.format( '%.4f', event.latitude ) latitude = latitudeText local longitudeText = string.format( '%.4f', event.longitude ) longitude = longitudeText local altitudeText = string.format( '%.3f', event.altitude ) altitude = altitudeText local accuracyText = string.format( '%.3f', event.accuracy ) accuracy = accuracyText local speedText = string.format( '%.3f', event.speed ) speed = speedText local directionText = string.format( '%.3f', event.direction ) direction = directionText -- Note that 'event.time' is a Unix-style timestamp, expressed in seconds since Jan. 1, 1970 local timeText = string.format( '%.0f', event.time ) time = timeText end end

and onSystemEvents are 

local function onSystemEvent( event ) if event.type == "applicationStart" then print("start") elseif event.type == "applicationExit" then print("exit") elseif event.type == "applicationSuspend" then print("suspend") -- want to get GPS handler while app is still in background -- want to run my timer function here. timer.resume() is giving warning not paused elseif event.type == "applicationResume" then print("resume") end end

my timer listener function is 

local function listener( event ) trtimer = trtimer - 1 print( "listener called"..trtimer ) if trtimer == 0 then -- now reset timer and call it again trtimer = 65 delayTimer = timer.performWithDelay( 1000, listener, trtimer ) end end

Problem is when I run the simulator, It only prints in Shell 

>>> GPS Running

>>> listener called 64

>>> listener called 63

>>> listener called 62

>>> listener called 61

>>> listener called 60

>>> listener called 59

>>> suspend

>>> WARNING: timer.resume( timerId ) ignored b/c timerId was not paused.

I want it like this

>>> GPS Running

>>> listener called 64

>>> GPS Running

>>> listener called 63

>>> GPS Running

>>> listener called 62

>>> listener called 61

>>> listener called 60

>>> listener called 59

>>> suspend

>>> listener called 58

>>> listener called 57

>>> listener called 56

>>> listener called 55

>>> listener called 54

>>> listener called 53

>>> listener called 52

>>> listener called 51

>>> resume

>>> listener called 50

>>> listener called 49

>>> listener called 48

>>> listener called 47

I understand GOS running will not be print in simulator but what about the timer why it is giving me error even if i use timer.resume(delimiter) under application suspend?

Thanks for help.

Kind regards

Ali

Did you find any solution regarding this? I am kinda facing the same issue…