位置更新方法在Blackberry上过于频繁地调用

时间:2012-11-29 11:19:16

标签: blackberry java-me gps jsr179

我有3部GSM手机和3部verizon(CDMA)手机。我有一个BB应用程序,其中位置监听器设置为5分钟的间隔。

对于2个verizon电话,应用程序的位置更新方法会被频繁调用。对于其余部分,位置监听器定期以5分钟的间隔进行呼叫。

可能导致这种行为差异的原因是什么?

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 个答案:

答案 0 :(得分:2)

您正在设置标准,如果locationInterval == 0或默认速率(每秒一次),则每300秒更新一次。这真的是你想要的吗? locationInterval在哪里初始化?程序运行时它的价值如何变化?