In this method you add all your class properties to the parcel in preparation for transfer. It handles the process of copying your object data into a parcel for transmission between activities and then re-creating the object on the other side. Start by adding the following into a new class file in your project. Parcelable is an Android only Interface used to serialize a class so its properties can be transferred from one activity to another.įirst create a class to hold info about each property. Java has had the ability to serialize objects for a while, but it’s a slow process as the system needs to perform heavy lifting to move the data.
Since objects can contain any number of mixed data types you can’t use putExtra to move values across. What should you do when you want to pass an object and its data from one activity to the other? You use the parcelableinterface Introducing the Parcelable Interface This works well for basic data types such as string, bool, and Integer but doesn’t work for objects. getStringExtra ( 'name' ) Integer age = intent. putExtra ( 'age', 26 ) //inside second activity Intent intent = getIntent ( ) String suburb = intent. The idea is to make the process of passing different types of data easy as: //Inside first activity Intent intent = new Intent ( MainActivity. Part of the process is sending data between activities and you do that via the putExtra and getExtra methods of our intent object.