Android GPS在完成后保持激活状态()
从活动(UI)中,我调用一个类来获取我的位置。 在活动的onPause中,我试图阻止听众,但状态栏中的GPS图标一直闪烁,在更多设备上就是这样(我听说这是HTC的问题) 有人能告诉我如何解决这个问题吗Android GPS在完成后保持激活状态(),android,gps,listener,locationmanager,locationlistener,Android,Gps,Listener,Locationmanager,Locationlistener,从活动(UI)中,我调用一个类来获取我的位置。 在活动的onPause中,我试图阻止听众,但状态栏中的GPS图标一直闪烁,在更多设备上就是这样(我听说这是HTC的问题) 有人能告诉我如何解决这个问题吗 The GPS location class: public GPSLocation (Context context) { myContext = context; LocatieManager=(LocationManager)myConte
The GPS location class:
public GPSLocation (Context context) {
myContext = context;
LocatieManager=(LocationManager)myContext.getSystemService(Context.LOCATION_SERVICE);
}
public void StopLocationListeners(){
// LocationManager LocatieManager=(LocationManager)myContext.getSystemService(Context.LOCATION_SERVICE);
LocatieManager.removeUpdates(netwerklistener);
LocatieManager.removeUpdates(gpslistener);
LocatieManager.removeGpsStatusListener(gpsStatusListener);
}
在UI活动中,我调用mGPSLocation.StopLocationListeners()在onPause方法中使用code>,但这不起作用。任何人都可以帮助我,并给我一个提示,为什么这是不可能的
谢谢您正在通过公共方法关闭GPS。但是你怎么能如此确定,当前正在运行的对象正在接近呢?我的意思是,您的location类可能有多个对象。为此,您需要使用static,以便在关闭GPS时,它将仅关闭特定的GPS。调用此命令后
mGPSLocation.StopLocationListeners();
您可以通过将LocationListener的对象设置为null来停止它。。放这条线
LocatieManager=null
在StopLocationListeners()方法中..您好,谢谢,唯一的问题是我得到了一个Nullpointer异常,因为后台仍在运行。您在这三行LocatieManager.removeUpdates(netwerklistener)之后放了这一行“LocatieManager=null”;LocatieManager.RemoveUpdate(gpslistener);LocatieManager.removeGpsStatusListener(gpsStatusListener);。。是吗?是的,但我想还有另一个物体在运行。它在调用LocatieManager的位置提供了一个空指针,但它不应该再调用LocatieManager,因为应用程序已关闭。我一直在看……我觉得情况就是这样。并非所有正在运行的对象都已关闭。但是我应该让这个类是静态的吗?因为这是不允许的。不,您可以将方法和变量设置为静态。那会很好的谢谢,我也有一个mylocation覆盖非静态,但它现在可以工作了!伟大的