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

How to send an object from one Android Activity to another using Intents?

How can I pass an object of a custom type from one Activity to another using the putExtra() method of the class Intent?

2 Answers

You can send serializable object through intent

// send where details is object
ClassName details = new ClassName();
Intent i = new Intent(context, EditActivity.class);
i.putExtra("Editing", details);

ClassName model = (ClassName) getIntent().getSerializableExtra("Editing");


Class ClassName implements Serializable {
Your class should implement Serializable or Parcelable.

public class MY_CLASS implements Serializable

Once done you can send an object on putExtra

intent.putExtra("KEY", MY_CLASS_instance);


To get extras you only have to do

Intent intent = getIntent();
MY_CLASS class = (MY_CLASS) intent.getExtras().getSerializable("KEY");

If your class implements Parcelable use next

MY_CLASS class = (MY_CLASS) intent.getExtras().getParcelable("KEY");

Login / Signup to Answer the Question.