is there a way to calculate once something instead once per second?
is there a way to calculate once something instead once per second?
Let's say it's sunrise/sunset. The easiest way is keep track of the last time it was calculated, and only do it again if the day has chaned. you can get the day with Gregorian.info.
var riseSetDay=99;
var sunrise,sunset;
function onUpdate(dc) {
//get today from Gregorain.info()
if(riseSetDay!=today) {
//calcuate sunrise and sunset
riseSetDay=today;
}
//other stuff
}thanks,
my problem is this: i got data from
x = App.getApp().getProperty(y);
and then i want to make a operation like this
var z = (y*4); wherever
but i want to optimize memory and do this only once so, where do i should do that operation? or should the operation be hidden const or something like that
on function initialize() also calculates once per second???
Let's start with you shouldn't be doing the getProperty in onUpdate. Put it in your view's initialize and store it in a class variable, so you can just use it in onUpdate. initialize() for the view is only run once (when your app starts).
i´m using getProperty on initialize, so if i do maths on initialize only runs once?
If you do it in initialize, yes.
For things like this, adding a System.println() call can help you see what's called and when.