Skip to content Skip to sidebar Skip to footer

Sending Bundle To Another Activity

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 (se

Solution 1:

Bundleb=newBundle();
b = toBundle(app.getHotelList().get(position));
intent.putExtras(b);
startActivity(intent);




//In your next activity//Create another Bundle object and get the string by nameBundlebundle= getIntent().getExtras();
if(bundle!=null){
 StringhotelName= bundle.getString("hotelname");
}

Solution 2:

You must use exact key sent:

StringhotelName= b.getString("hotelname");

Updated!

Solution 3:

Use Intent.putExtra(Bundle) method.

 intent.putExtra(b);

Solution 4:

Activity A (sending bundle): intent.putExtra("Hotel Bundle", b);

Activity B (loading the bundle): getintent().getExtra("Hotel Bundle");

not getintent().getExtra*s*

Solution 5:

Instead of using your toBundle method, you should implementParcelable, and write your Object to an Intent.

Post a Comment for "Sending Bundle To Another Activity"