I am trying to send a bundle from one activity to another. When I load the bundle in the recieving activity all the information seems to be null. Here is some code:
Bundle b = new Bundle();
b = toBundle(app.getHotelList().get(position));
intent.putExtras(b);
startActivity(intent);
//In your next activity
//Create another Bundle object and get the string by name
Bundle bundle = getIntent().getExtras();
if(bundle!=null){
String hotelName = bundle.getString("hotelname");
}
Activity A (sending bundle):
intent.putExtra("Hotel Bundle", b);
Activity B (loading the bundle):
getintent().getExtra("Hotel Bundle");
not getintent().getExtra*s*
You must use exact key sent:
String hotelName = b.getString("hotelname");
Updated!
I don't know if anyone still needs this but, in your intent.putExtra("Hotel Bundle", b);
It's either you send just intent.putExtra(b);
so you can get the data via
Bundle b = this.getIntent().getExtras();
String hotelName = b.getString("hotelname");
or if you want to keep the Hotel Bundle
key
Bundle b = this.getIntent().getBundleExtra("Hotel Bundle");
String hotelName = b.getString("hotelname");
Sorry, I needed the answer here, so might as well help those who run into this. Cheers.
Use Intent.putExtra(Bundle)
method.
intent.putExtra(b);
Instead of using your toBundle method, you should implement
Parcelable, and write your Object to an Intent
.