Search code examples
javaandroidandroid-intentmodelparcelable

How to send an object of a model in Intent


I have a model and it implements the Parcelable interface, on my MainActivity I've like this

ArrayList<Model> modelList = new ArrayList<>();
for(int i = 1; i <= 5; i++)
modelList.add(new Model( "name "+ i , "number "+ i));

And I have a ListView of this modelList items.

What I'm trying to do is that when the user clicks on an item of the list I use Intent and put its extra like modelList.get(position)

I just want to put a specific object of the model, and not the whole model like intent.putParcelableArrayList("KEY", modelList)


Solution

  • You might just need to do this

    Intent().putExtra("name", yourModel)

    putExtra has many overloads one of them is putExtra(name : String, value : Parcelable)