system.getTimer() help

Hey guys,

I’m currently making an app which uses the system.getTimer() function to mark a time when the app suspends and then marks it again when the app is resumed. However, when i suspend the app, the system time suspends as well. Therefore i can not calculate the time elapsed.

Does anyone know a way to get around this?

This is what i have so far:

[code]

local bg = display.newRect( 0, 0, 320, 480 )
local minsText = 0
local secsText = 00

local t = system.getTimer()

local timeText = display.newText(minsText… “:0” …secsText , 40, 40, “Helvetica”, 24)
timeText:setTextColor(0,0,0)

local Btn = display.newRect( 70, 70, 32, 48 )
Btn:setFillColor (0, 0, 0)

local function updateTime (event)
secsText = secsText + 1

if secsText < 10 then secsText = “0” …secsText elseif secsText > 59 then
secsText = 00
minsText = minsText+1
end
timeText.text = minsText … “:” …secsText
end
Timer = timer.performWithDelay(1000, updateTime, 0)
local function suspend (event)
if( event.type == “applicationSuspend” ) then
print(“applicationSuspend”)

t1 = system.getTimer()
print(“t1 =” … t1)
end
end
function resume (event)
if ( event.type == “applicationResume” ) then
print(“applicationResume”)

t2 = system.getTimer()
local ms = t2 - t1
print("elapsed milliseconds = " … ms)
print (“t2 =” … t2)

local floor = math.floor

secsText = floor(secsText + (ms / 1000))
minsText= floor(minsText + (secsText / 60))

timeText.text = minsText … “:” … secsText

end
end
Runtime:addEventListener (“system”, suspend)
Runtime:addEventListener (“system”, resume) [import]uid: 67534 topic_id: 22784 reply_id: 322784[/import]

Anyone? [import]uid: 67534 topic_id: 22784 reply_id: 90975[/import]

Please can some one help me? I’m so close to completing my app, and I’ve run into a brick wall… [import]uid: 67534 topic_id: 22784 reply_id: 91045[/import]

Do you have another thread about this I’ve already responded to, or was that someone else?

In any case, if that was you, same answer again - get the time, not use the system timer - os.time() api, use on suspend and on resume and on resume calculate time difference :slight_smile:

Peach [import]uid: 52491 topic_id: 22784 reply_id: 91064[/import]

Ah it was me, I apologise for double posting but I’m really close to getting my first app out there, so I was kinda desperate. [import]uid: 67534 topic_id: 22784 reply_id: 91091[/import]

If you make a post and don’t get answers in a timely manner, rather than double posting, tweet @peachpellen and as soon as I see it I’ll try to get an answer for you :slight_smile:

I believe you were a test driver last I looked, am I mistaken or are you now licensed? If so, congrats! [import]uid: 52491 topic_id: 22784 reply_id: 91113[/import]

hi Peach. I don’t know if I have a problem with my app or its the right behavior, but when I press the home button the applicationSuspend isn’t fired immmediately. Its called after I back to the application, at this moment the applicationSuspend AND applicationResume events are fired, BOTH at the same time. So, I can’t manage the on suspend functionality in my app. [import]uid: 104813 topic_id: 22784 reply_id: 94796[/import]