0

I can't seem to remove the listener for the update event for geolocation on Android.

I wanna stop the Geolocation on deactivate:

NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, onAppDeactivate);



private function onAppDeactivate(e:Event):void {

        if (Geolocation.isSupported) {
            if (geolocation != null) {
                geolocation.removeEventListener(GeolocationEvent.UPDATE, onGeolocationUpdate);
                geolocation.setRequestedUpdateInterval(0);
                geolocation = null;
            }
        }
}

I started with just removing the listener, but since that didn't work I also tried removing the geolocation all together. Still no luck..

Any hints?

Tinelise
  • 386
  • 4
  • 16
  • Where do you define the geolocation variable? Are you sure it is not null? Where do you define geolocation? Where do you add the event listener for GeolocationEvent.UPDATE? What makes you think the listener is not being removed? What makes you think that Geolocation events are firing while the app is deactivated? Is this a mobile application or a desktop application? – JeffryHouser Sep 04 '12 at 12:38
  • Geolocation is defined in my first views viewActivate after some other stuff. This is also where I add the listener for UPDATE. It's a mobile application. I know it runs the code and that geolocation is not null because I updated a variable after every line in the appDeactivate code and checked it again on activate. But the geolocation symbol on my android does not go away.. – Tinelise Sep 05 '12 at 05:41

1 Answers1

0

I had an app that uses Geolocation too, and if what you want is to save the battery from draining fast, you have to call the geolocation.setRequestedUpdateInterval(INTERVAL_MILLIS) method with a high value for INTERVAL_MILLIS (in my case i use 60000 that is 1 min).

But as the (documentation) says, the OS will decide the update interval for the GPS, ant the value we pass serves a a "hint" to the update interval.

And specifically on Android, the GPS icon will stay on as long as you have the GPS enabled (and it will consume power) but will no drain you battery fast as the update interval will be high.

So the best thing you can do is actually request a large update interval when you app deactivates.

polloss
  • 406
  • 4
  • 7