Hey people,
I have an Interval in my app that checks the idle time of the user every 30 secs, when the user has been idle for longer then 5 minutes the app will go to the login screen again, at that point i want to clear my interval but it doesn't seem to work because the variable of the interval is not recognized at the place im trying to clear it.. I tried setting it in the app properties and clear it from there, but that didn't work either.
So my question is, how can I clear an Interval that was created on an other page?
Regards, Niels
6 Answers
Accepted Answer
as an idea: put 2 app eventlisteners in your app.js: one for starting the interval and one for stopping it. You can fire those events from everywhere in your app (via Ti.App.fireEvent('myEventName');)
I now have this function:
Ti.App.addEventListener('createIdleInterval', function(status) { if(status == 'start'){ var idleTimerInterval = setInterval(checkIdleTimeOnInterval, 5000); } if(status == 'stop'){ clearInterval(idleTimerInterval); } });And I call it like this:
Ti.App.fireEvent('createIdleInterval', 'start');
But nothing happens :)
did it like this now:
Ti.App.fireEvent('createIdleInterval', {action:'start'});
and in my function:
if(status.action == 'start')
seems to work, thanks for the idea!
Please mark Soeren's answer as accepted. Saves others some time, and gives him the credit he deserves.
Tested this today, but still doesn't work.. (thought it did)
So im looking for another solution again :)
Still the same question: how can I clear an Interval that was created on another page?
What exactly is not working?
Have you done any debugging like alerts when calling the function? You should define the var idleTimerInterval outside the function. Like
var idleTimerInterval; Ti.App.addEventListener('createIdleInterval', function(status) { if(status == 'start'){ idleTimerInterval = setInterval(checkIdleTimeOnInterval, 5000); } if(status == 'stop'){ clearInterval(idleTimerInterval); } });and: do you have your function "checkIdleTimeOnInterval" also in the app.js file so that you can call it from within the eventlistener?
Have you checked the debug log for details?
Your Answer
Think you can help? Login to answer this question!