LocationUpdate method getting called too frequently on Blackberry

127 Views Asked by At

I have a 3 GSM phones and a 3 verizon (CDMA) phones. I have a BB application in which the location listener is set to a 5 minute interval.

For 2 of the verizon phones the application's location update method gets called frequently. For the rest, the location listener gets called at a regular 5 minute interval.

What could be causing this difference in behavior?

public synchronized void locationUpdated(LocationProvider locationProvider, Location location) {
        if (enabled) {

            if (blackberryProvider != null) {
                try {                       
                    constructCriteria(GPSInfo.GPS_MODE_CELLSITE);
                    gpsUpdate();
                } catch (LocationException e) {
                   log stuff//  
                }
            }
        }
    }


    private void gpsUpdate() throws LocationException, InterruptedException {
        try {
            String gpsMode = null;
        if (bbCriteria.getMode() == GPSInfo.GPS_MODE_CELLSITE) {
                gpsMode = "cellsiteMode";
            }


            if (gpsMode == "cellsiteMode" && gpsMode.length() > 0 && bbProvider != null) {
                // variable declaration

                try {
                    bbLocation = (BlackBerryLocation) bbProvider.getLocation(10);
                } catch (LocationException e) {

                    bbLocation = null;
                }

                if (bbLocation != null) {
                    // do stuff
                    // store location in the database   


                        }

                    }

                }

            }
        }
    }





private void constructCriteria(final int mode) {
    blackberryCriteria = null;
    blackberryProvider = null;
    blackberryCriteria = new BlackBerryCriteria();
    blackberryCriteria.setSatelliteInfoRequired(true, false);



     if (mode == GPSInfo.GPS_MODE_CELLSITE) {
        setCriteraForCellSite();
    }
    try {
        blackberryProvider = (BlackBerryLocationProvider) LocationProvider.getInstance(blackberryCriteria);

        if (iLocationListner == null) {
            iLocationListner = new ILocationListner();
            blackberryProvider.setLocationListener(iLocationListner, locationInterval == 0 ? 300 : locationInterval, -1, -1);
        } else {
            blackberryProvider.setLocationListener(iLocationListner, locationInterval == 0 ? 300 : locationInterval, -1, -1);
        }
    } catch (LocationException lex) {
        Logger.log("LocationEventSource constructor", lex);
        return;
    } 

}
1

There are 1 best solutions below

3
On

You are setting your criteria to update every 300 seconds if locationInterval == 0 or at the default rate (once per second) otherwise. Is this really what you want? Where is locationInterval initialized? How does its value change as the program runs?