Home > DeveloperSection > Forums > How to Pass object to another activity in android?
Allen Scott

Total Post:46

Posted on    November-19-2014 1:58 AM

 Android Java  OOPS 

 1 Reply(s)
 1037  View(s)
Rate this:

I have found this way to do this

Student student = new Student (18,"Zar E Ahmer");

Intent i = new Intent(this, B.class);

i.putExtra("studentObject", student);


The problem is that if the object changed in the first activity No change took place in the another activity. I thought how to make it like a constructor that no copy of the object is pass but the object it self.

Brad Pitt
Brad Pitt

Total Post:61

Posted on    November-19-2014 7:21 AM

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

PSEUDO code:

//to pass :

   intent.putExtra("MyClass", obj); 

// to retrieve object in second Activity


Don't want to miss updates? Please click the below button!

Follow MindStick