2011-11-22 80 views
2

我的活动实现LocationListener的如下安卓:释放GPS

public class LoginActivity extends Activity implements LocationListener {} 

我的LocationManager去如下

mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, this); 

我可以使用有关该方法的当前GPS位置。

现在我需要在活动关闭时释放GPS。

所以我的onPause方法如下。

@Override 
protected void onPause() { 
    mlocManager.removeUpdates(this); 
    //System.exit(0); 
    super.onPause(); 
} 

但是,这并不释放GPS。有人可以帮我吗。提前致谢。

回答

1

我可能还有另一个位置监听器,它叫做requestLocationUpdates()

如果不是,您应该致电removeUpdates()finish()onStop()onDestroy()只是为了确保。这应该够了吧。

1

试试这个,让我知道发生了什么。

@Override 
    protected void onPause() { 
     super.onPause(); 
      mlocManager.removeUpdates(this); 
      mlocManager.removeGpsStatusListener(this); 
    } 

现在我需要在活动关闭时释放GPS。

然后把这个代码放在onStop()onDestroy()的活动中。