Points To Remember
You can send an Object from one Activity to another using two ways- Make a class extend Parcelable
- Make class Serializable
Parcelable is a faster way to send and receive data, but it needs a lot of code to be written and manage in a particular way, however Serializable is a Java technique and is much simpler than the former way.
Send Object from one Activity to Another Activity using Serializable
We will make a POJO class Person that needs to be sent from ActivityOne to ActivityTwo. The Person class just needs to implement the serializable interface.The code may look like below
- Activity to send Object
intent.putExtra("name", object);
- Activity to receive object
Object object = (Object) getIntent().getSerializableExtra("name");
The full code example looks like the following
Comments
Post a Comment