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]
