views:

43

answers:

1

Hello, I got the following problem: We registered different ProximityListeners in JavaME to a LocationProvider. Everything works fine with the external events emulation, and the proximityEvent method is triggered correctly.

Problem: After "one usage", the method is not triggered anymore. The LocationProvider still works good, because the position changes, but the ProximityListener does nothing, untill you add it again.

API says: Regardless of the state, the ProximityListener remains registered until the application explicitly removes it with LocationProvider.removeProximityListener or the application exits.

But I can't see that behaviour, is there any bug or a common missunderstanding?

A: 

I've only ever really used JSR 179 on Nokia Series 60, but I recall a bug when using it that may be causing your problems too. When you set your ProximityListener on your LocationProvider, you need to retain a reference to the LocationProvider in your code, otherwise it will be cleaned up as "garbage" of some form. Example:

private void startLocationListener() throws Exception {
    LocationProvider lp = LocationProvider.getInstance(null);
    lp.setLocationListener(this);

    // Error on S60, as the location provider is about to go out of scope,
    // and we won't hear about any location updates!  Fix this by declaring lp
    // outwith this method
}

ISTR finding someone else who had experienced this problem too (I think it was on Forum Nokia), at the time when I experienced it, however I can't find the link now.

Hope this helps.

funkybro