UPDATE # 2. My initial question was resolved by the kindness of the two who answered. Apparently, I need to ask a new question that the received code during its launch does not stop GPS. But now there are no errors, so I would mark this as a solution if I knew how :-)
UPDATE
I have a “working” code thanks to the comments, the only problem is that it does not do what it should do. It works in that there are no errors.
To make it work, I added it globally at the top of the action.
protected LocationListener ll;
protected LocationManager lm;
And used this code OnPause
@Override
protected void onPause() {
if(lm != null) {
lm.removeUpdates(ll);
}
ll = null;
lm = null;
super.onPause();
}
. GPS-. , , GPS, . GPS . , , . , lm.removeUpdates(ll) , .
--------------- -------------------------
OnPause, GPS. , , stackoverflow , , Eclipse.
GPS ( ):
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textLat = (TextView)findViewById(R.id.textLat);
textLong = (TextView)findViewById(R.id.textLong);
textTimex = (TextView)findViewById(R.id.textTimex);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
class mylocationlistener implements LocationListener{
@Override
public void onLocationChanged(Location location) {
if (location != null)
{
double pLat = location.getLatitude();
double pLong = location.getLongitude();
long pTime = location.getTime();
DecimalFormat df = new DecimalFormat("#.######");
textLat.setText(df.format(pLat));
textLong.setText(df.format(pLong));
textTimex.setText(Long.toString(pTime));
}
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
}
, .
@Override
public void onPause() {
lm.removeUpdates(locationListener);
super.onPause();
}
, lm, , . , , .
- ...