Clear Interval from other page

You must Login before you can answer or comment on any questions.

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?

— answered 10 months ago by Soeren Damrau
answer permalink
4 Comments
  • Devining the variable outside the function did the trick, thanks

    Should have been a bit more clear with what happened/didn't happen..

    — commented 10 months ago by Niels Brink

  • great to hear that it works now! I would be happy if you mark the question as solved, thanks a lot!

    — commented 10 months ago by Soeren Damrau

  • oh sorry - just saw, that you allready marked the upper question as solved. thanks!

    — commented 10 months ago by Soeren Damrau

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!