GeoLocation adding and removing listeners

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

I'm trying to conserve battery usage of a device depending on what areas of the app are being used. I've added code as such:

Ti.Geolocation.addEventListener('location', locationCallback);
and
Ti.Geolocation.removeEventListener('location', locationCallback);
what I'm wondering is, if I would make duplicate addEventLIsteners, do I need to perform the removeEventListener the same number of times, or if an event is already beng listened for does it not create a duplicate?

So to have a ridiculous example, if I had this:

Ti.Geolocation.addEventListener('location', locationCallback);
Ti.Geolocation.addEventListener('location', locationCallback);
Ti.Geolocation.addEventListener('location', locationCallback);
would there be three listeners? Or would it recognize the listener as already in existence and not create a new one...

Could I close remove it with a single request as such?

Ti.Geolocation.removeEventListener('location', locationCallback);
Or would I need to keep track and of each time the listener is added and remove it accordingly, and either close each one that is called, or more logically make sure an event listener isn't created if a listener is already active.

Currently, I'm keeping track of the listener state and just wondering if that is necessary or not...

1 Answer

I know this might not be the exact help you are looking for, but in order to answer that you have to actually peek into the java/objc Accelerator source code, and it may take some time. But what you can do is to actually test& observer them yourself:-

1) Just do 1 addEventListener and observe the consistent pattern eg locationCallback is always called every 1 minute. 2) Do the same thing as above, but add 3 times for an example, with the same callback function, and observe again. 3) Do (2), and this time removeEventListener once, and observe - is the callback function called now?

Your Answer

Think you can help? Login to answer this question!