I'm developing an Android app using apache cordova tools on visual studio. I need an event that triggers hourly and do something, Is using the setInterval the best option or not?
thanks.
I'm developing an Android app using apache cordova tools on visual studio. I need an event that triggers hourly and do something, Is using the setInterval the best option or not?
thanks.
Yes, I think setInterval
is a useful solution. But with strong possibility, you will improve your app as a service. If you need some additional information you might visit this site; http://www.tipsfromsiliconvalley.com/2013/07/06/create-a-service-on-android-with-phonegap-application/
And a sample application of setInterval
method;
var runAt = 60,
current = 1;
if($.session.get('username')) {
$(document).ready(function () {
var idleInterval = setInterval(timerIncrement(), 60000);
})
function timerIncrement() {
current = current + 1;
if (current == runAt) {
current = 0;
// DO SOMETHING
}
}
}
Good luck..
You don't describe what you are trying to do with running code every hour. If you are trying to do a polling operation (checking for updates on a server), you might want to rethink your design.
I would suggest that you use push notification to notify clients that an update is available. Register each device for push notifications (there is a cordova plugin), save the device ids on your server. Then when data is refreshed, send a notification to your clients to refresh. On the device, you can register for these notifications without any alerts, so that the message and update are silent and in the background for the user.