How to call a function in specific time interval when the app is in background

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

I want to call a function in specific interval when my app goes into background. I have referred kitchen sink app for background task, but how to achieve this.

1 Answer

Accepted Answer

you can do something like this, as you gone through the kitchen sink app for background process. so create a JS file say x.js, just do.

function myFunc()
{
    //your code
}
 
//set the interval
 
setInterval(myFunc,2000) //this will run the function for every 2 sec.
//now in you app.js

var service = Ti.App.iOS.registerBackgroundService({url:'x.js'}); you are good to go..

— answered 1 year ago by Ajeet pratap Maurya
answer permalink
6 Comments
  • My function is in another class I want to reuse it here..

    — commented 1 year ago by titanium dev

  • you can apply the commonJS approach like say you have file alpha.js where your function is there.

    do like this

    exports.myFunct = function()
    {
        //your code
    }
    now in your x.js which I describe above write this
    var callMyFunction = require('alpha');
     
    function callFunction()
    {
        callMyFunction.myFunct();
    }
     
    setInterval(callFunction,2000);

    — commented 1 year ago by Ajeet pratap Maurya

  • Thanks for the quick reply, let me try it..

    — commented 1 year ago by titanium dev

  • Show 3 more comments

Your Answer

Think you can help? Login to answer this question!