在一个意图中询问android位置,然后在另一个意图中获得

在一个意图中询问android位置,然后在另一个意图中获得,android,android-intent,gps,Android,Android Intent,Gps,我知道如何获取GPS位置,有很多教程 有足够的时间我可以得到GPS定位,但时间是关键。我想问一下AP何时打开并准备好用于其他目的的当前位置;在新的意图中,只需请求一次更新,但位置已设置 现在我做的很简单: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings); locationMa

我知道如何获取GPS位置,有很多教程

有足够的时间我可以得到GPS定位,但时间是关键。我想问一下AP何时打开并准备好用于其他目的的当前位置;在新的意图中,只需请求一次更新,但位置已设置

现在我做的很简单:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("GPS Location");
    alertDialog.setMessage("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    alertDialog.setIcon(R.drawable.ic_launcher);
    alertDialog.show();
    super.onPause();
    locationManager.removeUpdates(locationListener);
}

更好的方法是使用服务获取位置。可以在需要扩展的应用程序对象的“oncreate”上启动该服务。位置详细信息也可以作为成员变量存储在应用程序对象上,这样任何活动或服务都可以获得它

但是,如果您当时已经收到了位置信息,那么您也可以通过intent传递位置信息