Primitive data types like string, integer, float, etc. can be passed through intents, by putting the data with unique key in intents and send it to another activity. To send Java class objects from one activity to another activity using the intent, object passing techniques are Serialization and Parcelable. Parcelable is faster than Serialization makes it a preferred choice of approach while passing an object.
Serializable is a standard java interface and Parcelable is an Android-specific interface. Serializable interface implemented by java.io.Serializable
and Parcelable interface by android.os.Parcelable
.
Serialization example
public class Person implements Serializable { // Implement methods } // Create new Activity with extra, and put data Person enumb = new Person(); Intent intent = new Intent(getActivity(), NewActivity.class); // Second param is Serializable intent.putExtra("en", enumb); startActivity(intent); // Retrive data from new activity: public class NewActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); if (extras != null) { // Obtaining data Person en = (Person)getIntent().getSerializableExtra("en"); } } }