Android: How to pass Parcelable object to intent and use getParcelable method of bundle? Android: How to pass Parcelable object to intent and use getParcelable method of bundle? android android

Android: How to pass Parcelable object to intent and use getParcelable method of bundle?


Intent provides bunch of overloading putExtra() methods.

Suppose you have a class Foo implements Parcelable properly, to put it into Intent in an Activity:

Intent intent = new Intent(getBaseContext(), NextActivity.class);Foo foo = new Foo();intent.putExtra("foo ", foo);startActivity(intent);

To get it from intent in another activity:

Foo foo = getIntent().getExtras().getParcelable("foo");

Hope this helps.


Parcelable p[] =getIntent().getParcelableArrayExtra("parcel");


Sender Activity:

val intent = Intent(this, RestaurantDetails::class.java)        intent.putExtra(Constants.RESTAURANT, restaurant)        startActivity(intent)

Receiver Activity:

        val restaurant = intent.getParcelableExtra<Restaurant>(Constants.RESTAURANT)