1

Google マップ フラグメントの別のアクティビティに経度変数と緯度変数を渡そうとしています。これまでのところ、私はこれを行うことができました

Intent i = new Intent(Main.this, Main2.class);
i.putExtra(Double.toString(gettextLong), xLocation.getLongitude());
i.putExtra(Double.toString(gettextLat), xLocation.getLatitude());'

他のアクティビティでそれを受け取るにはどうすればよいですか?

4

3 に答える 3

1

試す:

Intent i = new Intent(Main.this, Main2.class);
i.putExtra("lon", xLocation.getLongitude());
i.putExtra("lat", xLocation.getLatitude());

このような:

int lat = getIntent().getExtras().getDouble("lat");
int lon = getIntent().getExtras().getDouble("lon");
于 2013-07-22T12:09:32.497 に答える
1

のような関連するキーを与える

Intent i = new Intent(Main.this, Main2.class);
i.putExtra("longitude", xLocation.getLongitude());
i.putExtra("latitude", xLocation.getLatitude());

および Main2 アクティビティで

Bundle extras = getIntent().getExtras(); 
if(extras !=null && extras.getDouble("latitude") != null && extras.getDouble("longitude") != null) { 
double lat = extras.getDouble("latitude");
double lng = extras.getDouble("longitude");
}
于 2013-07-22T12:10:57.843 に答える
0

2 番目のアクティビティでgetIntent()getDoubleExtra()を使用します。しかし、別の方法で渡します。putExtra の最初の引数は String である必要がありますが、後で 2 番目のアクティビティで使用する必要があるため、それを知っておく必要があります。お気に入り:

public static final String FIRST = "firstArgument";

i.putExtra(FIRST, xLocation.getLongitude()); 

そして Main2 では:

double i = getIntent().getDoubleExtra(Main.FIRST, 0);
于 2013-07-22T12:04:00.897 に答える