Skip to main content

How To Send Array Of Objects To Activity - Android Parcelable

Creating parcelable object is the solution to send an array of objects to activity. Many times we required to send important data and information from one activity to another activity, we use the Android Intent and bind the integer, long, String etc in the extra parameter of the intent for this purpose.  But, what if we have to send the array of objects to any activity?  So, here we are going to learn about Android Parcelable objects which can be used to send and receive the array of objects to any activity.

Android Parcelable class to Send Array Of Objects To Activity

Parcelable  Class to create and Send Array Of Objects To Activity

In this section, we will create a class which implements parcelable, so that we can use this object class to create and sends an array of objects to Activity as a parcel to the second activity. The class which implements the parcelable interface should also have a non-null static field called ofCREATOR a type that implements the Parceable.Creator interface.

A typical implementation of Parcelable Interface is as given below.

package com.nplix.androidparcelableobject;
import android.os.Parcel;
import android.os.Parcelable;/**
* Created by PK on 4/17/2017.
*/public class Data implements Parcelable{
private long ID;
private String FirstName;
private String LastName;public long getID() {
return ID;
}public void setID(long ID) {
this.ID = ID;

public String getFirstName() {
return FirstName;

public void setFirstName(String firstName) {
FirstName = firstName;

public String getLastName() {
return LastName;

public void setLastName(String lastName) {
LastName = lastName;

public int describeContents() {
return 0;

public void writeToParcel(Parcel parcel, int i) {


public static final Parcelable.Creator CREATOR= new Parcelable.Creator(){
public Data createFromParcel(Parcel in) {
return new Data(in);

public Data[] newArray(int i) {
return new Data[i];
public Data(Parcel in){

Create Parcelable Array object in First Activity

In our First Activity, we will create the List of the parceable object and pass the object to Second Activity. Below is the complete code of First Activity.
package com.nplix.androidparcelableobject;

import android.content.Intent;
import android.os.Parcelable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

public class FirstActivity extends AppCompatActivity {
private List<<Data>> dataList;
protected void onCreate(Bundle savedInstanceState) {
//Create Data and add to list
dataList= new ArrayList<<Data>>();
Data data= new Data();
// Create Intent and assign the parceable List for sending to second activity on btn click
Button sndBtn= (Button) findViewById(;
sndBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent= new Intent(FirstActivity.this,SecondActivity.class);
intent.putParcelableArrayListExtra("data",(ArrayList) dataList);

Read the List of Parcelable Object data in Second Activity

For reading the List of Parcelable Object we need to follow below steps.

First, create a list or array as given below.

Declare the List with the type Data

private List<> recList;

Initialize the Array of objects

recList=new ArrayList<>();
recList =(ArrayList) getIntent().getParcelableArrayListExtra(data);

Read the data in Second Activity and print in log. For simplicity of this tutorial we are just printing the information into the logs.

But in the real scenario, you can use these object as per your requirement of the project.
Log.d("NPLIX:- ", "ID:"+ recList.get(0).getID()+"First Name:"+ recList.get(0).getFirstName()+"Last Name:"+ recList.get(0).getLastName());

Second Activity

 package com.nplix.androidparcelableobject;

import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

public class SecondActivity extends AppCompatActivity {
private List<Data> recList;
protected void onCreate(Bundle savedInstanceState) {
recList=new ArrayList<Data>();
recList = (ArrayList) getIntent().getParcelableArrayListExtra("data");

Log.d("NPLIX:- ", "ID:"+ recList.get(0).getID()+"First Name:"+
recList.get(0).getFirstName()+"Last Name:"+ recList.get(0).getLastName());


So Conclusion of the above short tutorial is that we need to create a POJO class for our object and that should implement the parcelable and implement all method to parcel and read the data. Both should be implemented in the same sequence so that second activity can read the object element in the same sequence as it was sent by first activity.


  1. […] If you would like to check the Java version of this tutorial you can check the  Send Array Of Objects To Activity – Android Parcelable […]

  2. I am attracted by the presentation of this article. This information about Parcel, is really good. I really appreciate your work. It is a gainful article for us. Keep posting. Thank you.
    Small Parcel Contract Negotiation


Post a Comment

Popular posts from this blog

Flutter How to Start Android Activity from Flutter View

Flutter and Dart is an excellent combination for creating the UI, but for accessing the platform-specific service we need to open platform-specific activity. So lets in this article we will explore how to start an android activity and access the service from Flutter View. Create a Project for this Android Activity Flutter View Demo Create a Project From File menu select the New Flutter Project Enter the project name Select the AndroidX support and click on next After the above, we step click on Finish We will have the following project structure created. Create the Second Activity in Android Just go to the android folder and open it in separate windows. We will have the following project structure. Create the Activity Just right-click on the Kotlin folder and create a blank activity from the menu. If you create the activity then you may be required to upgrade the Gradle and do some import. So Just click on update and wait for the project s

Kotlin Parcelable Array Objects Send To Activity

We know that IPC (Inter Process Communication) between the activity is an extremely important part of any application development. We often required that we need to send some data to other activity. For example, we may be required to send an array of data, data could be an Integer, String, Long, Double, Float or any other custom data objects. So, In this example, we are going to learn how to implement the Kotlin Parcelable Array object to send the data from one activity to second activity. What is Parcel? The parcel class is designed as a high-performance IPC transport. A Parcel can contain both flattened data that will be unflattened on the other side of the IPC, and references to live IBinde r objects that will result in the other side receiving a proxy IBinder connected with the original IBinder in the Parcel. Create Kotlin Parcelable Array Objects Parcelable is API for placing the arbitrary objects into the Parcel. In Actual in android app development, Parcelable is an interface

Create Custom EditText View in Android

We use the EditText for taking the input from the user and use it at several places in our project. We required to do lots of customization for each time and there are lots of redundant code we write. Writing and managing these redundant codes is very difficult for example if we want to change the look and feel of the view them we need to modify it at each place where our EditText is getting used. So to avoid these kinds of the problem we can create our own Custom EditText View by just. The EditText view is just an extension of the TextView with lots of editing option and properties that required for the user input. How To Create Custom EditText View For creating the Custom EditText we need to extend the AppCompatEditText and override all three constructors of the view as given below. import android.content.Context; import; import; import; import android.util.AttributeSet; public