相关疑难解决方法(0)

LocationManager.removeUpdates(侦听器)不删除位置侦听器

我的应用场景是我想跟踪员工的位置.我有一个广播接收器,它监听设备启动广播并注册一个报警管理器.当警报管理器滴答时,它会注册两个位置监听器,一个用于监听gps,另一个用于监听网络.我希望当我在onLocationChange()方法中获得第一个位置更新时,保存位置并取消注册该位置监听器,以便当警报管理器再次打勾时,它不会重复.要取消注册,我将位置侦听器作为静态对象来访问onLocationChange().但我发现它不是删除位置监听器.这是我的代码示例:

 public class BootTimeServiceActivator extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Calendar calendar = Calendar.getInstance();
        AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent mIntent = new Intent(context, MyBroadCastReceiver.class);
        PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, mIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 20 * 60 * 1000, mPendingIntent);


    }

    }

//..........

    public class MyBroadCastReceiver extends BroadcastReceiver{

    public static LocationManager locationManager;
    public static MyLocationListener networkLocationListener;
    public static MyLocationListener gpsLocationListener;



    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated …
Run Code Online (Sandbox Code Playgroud)

android locationlistener

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

locationlistener ×1