Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to pass an object from one activity to another on Android

I'm attempting to work at sending an object of my client class from one Activity and show it in another Activity.

public class Customer {

private String firstName, lastName, Address;
int Age;

public Customer(String fname, String lname, int age, String address) {

firstName = fname;
lastName = lname;
Age = age;
Address = address;

public String printValues() {

String data = null;

data = "First Name :" + firstName + " Last Name :" + lastName
+ " Age : " + Age + " Address : " + Address;

return data;

I need to send its object starting with one Activity then onto the next and afterward, show the information on the other Activity.
How can I achieve that?

2 Answers

One option could be letting your custom class implement the Serializable interface and then you can pass object instances in the intent extra using the putExtra(Serializable..) variant of the Intent#putExtra() method.


//To pass:
intent.putExtra("MyClass", obj);

// To retrieve object in second Activity

Note: Make sure each nested class of your main custom class has implemented Serializable interface to avoid any serialization exceptions. For example:

class MainClass implements Serializable {

public MainClass() {}

public static class ChildClass implements Serializable {

public ChildClass() {}
Implement your class with Serializable. Let's suppose that this is your entity class:


@SuppressWarnings("serial") //With this annotation we are going to hide compiler warnings
public class Deneme implements Serializable {

public Deneme(double id, String name) { = id; = name;

public double getId() {
return id;

public void setId(double id) { = id;

public String getName() {

public void setName(String name) { = name;

private double id;
private String name;

We are sending the object called dene from X activity to Y activity. Somewhere in X activity;

Deneme dene = new Deneme(4,"Mustafa");
Intent i = new Intent(this, Y.class);
i.putExtra("sampleObject", dene);

In Y activity we are getting the object.

Intent i = getIntent();
Deneme dene = (Deneme)i.getSerializableExtra("sampleObject");

Login / Signup to Answer the Question.