Reputation: 1330
I am trying to pass 2 double arrays from one activity to the other. However when I try to pass the values from the 2 arrays in the first activity to the arrays in the second activity I get just the values from the first array and its stored in both new arrays.
This is how I use the bundle to send the arrays
Bundle bund = new Bundle();
bund.putDoubleArray(endLatitudeStr, endLatitude);
intent.putExtras(bund);
Bundle bund2 = new Bundle();
bund2.putDoubleArray(endLongitudeStr, endLongitude);
intent.putExtras(bund2);
startActivity(intent);
And the on the receiving side I have:
Intent intent = getIntent();
mXmlRpcUrl = intent.getStringExtra("XmlRpcUrl");
mSessionID = intent.getStringExtra("SessionID");
mGetSavedTripFunc = intent.getStringExtra("GetSavedTripFunc");
Bundle bund = intent.getExtras();
endLatitude = bund.getDoubleArray(endLatitudeStr);
Bundle bund2 = intent.getExtras();
endLongitude = bund2.getDoubleArray(endLongitudeStr);
However the result is always just the values from the first array(in this case endLatitude) What am i doing wrong?
Upvotes: 1
Views: 597
Reputation: 3263
Why do you use 2 Bundles? Just use one ...
Bundle bundle = new Bundle();
bundle.putDoubleArray(endLatitudeStr, endLatitude);
bundle.putDoubleArray(endLongitudeStr, endLongitude);
intent.putExtra(bundle);
startActivity(intent);
and ...
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
endLatitude = bundle.getDoubleArray(endLatitudeStr);
endLongitude = bundle.getDoubleArray(endLongitudeStr);
Upvotes: 0
Reputation: 7
If i recall correctly you can only use one bundle because if you make another bundle it will replace the previous bundle so what you need to do is put the bund1 and bun2 on the first bundle then retrieve it use
Bundle bundle = new Bundle();
bundle = getIntent().getExtras();
String mystring=bundle.getString("bund1");
String mystring=bundle.getString("bund2");
Upvotes: 0
Reputation: 3633
Use same bundle object.
Bundle bund = new Bundle();
bund.putDoubleArray(endLatitudeStr, endLatitude);
bund.putDoubleArray(endLongitudeStr, endLongitude);
intent.putExtras(bund);
startActivity(intent);
Intent intent = getIntent();
mXmlRpcUrl = intent.getStringExtra("XmlRpcUrl");
mSessionID = intent.getStringExtra("SessionID");
mGetSavedTripFunc = intent.getStringExtra("GetSavedTripFunc");
Bundle bund = intent.getExtras();
endLatitude = bund.getDoubleArray(endLatitudeStr);
endLongitude = bund.getDoubleArray(endLongitudeStr);
Upvotes: 2