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:
Activity A (sending bundle):
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Intent intent = new Intent(HotelsActivity.this, EditHotelActivity.class);
Bundle b = new Bundle();
b = toBundle(app.getHotelList().get(position));
intent.putExtra("Hotel Bundle", b);
startActivity(intent);
}
});
the toBundle method is just adding strings from an object into the bundle. I have put logging statements in this method and the bundle is definately not null.
Activity B (loading the bundle):
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.edit_hotel);
setTitleFromActivityLabel (R.id.title_text);
// Retrieve sent bundle
Bundle b = this.getIntent().getExtras();
String hotelName = b.getString("hotelname");
if (hotelName == null)
MyLog.i(TAG, "IT IS NULL");
}
The loggin statement then prints “IT IS NULL” because for some reason hotelName is null but that is definately the correct key.
Can anyone help with this?
toBundle method:
public Bundle toBundle(HotelItem hotel) {
Bundle b = new Bundle();
b.putString("hotelname",hotel.getHotelName());
b.putString("hotel address", hotel.getHotelAddress());
b.putString("hotel telephone", hotel.getHotelTelephone());
b.putString("hotel website", hotel.getHotelWebsite());
return b;
}
You must use exact key sent:
Updated!