我有这个问题,当我想返回首页时,我从应用程序中使用GPS来获取经度和纬度。图标GPS总是从移动设备的顶部显示,如何在返回主屏幕后将其关闭
我的代码。
public class doctorlocation extends Activity implements LocationListener {
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
String lat;
String provider;
protected double latitude,longitude;
protected boolean gps_enabled,network_enabled;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.doctorlocation);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
//txtLat = (TextView) findViewById(R.id.textview1);
//txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
String str = "Latitude: "+location.getLatitude()+" \nLongitude: "+location.getLongitude();
Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
latitude=location.getLatitude();
longitude=location.getLongitude();
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
Toast.makeText(getBaseContext(), "Gps turned off ", Toast.LENGTH_LONG).show();
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
Toast.makeText(getBaseContext(), "Gps turned on ", Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude","status");
}
}
在使用这个代码onPause()
的那个Activity
。
@Override
protected void onPause() {
Log.i("onPause", "inside onPause");
super.onPause();
locationManager.removeUpdates(myLocationListener);//locationManager.removeUpdates(this) ;
locationManager = null;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句