Home >Java >javaTutorial >How to Pass Data Through an Intent Using Serializable in Android?
Passing Data through Intent using Serializable
To pass data through an Intent using Serializable, the class containing the data must implement the Serializable interface.
Consider the following implementation:
package com.ursabyte.thumbnail; import java.io.Serializable; import android.graphics.Bitmap; public class Thumbnail implements Serializable { private static final long serialVersionUID = 1L; private String label = ""; private Bitmap bitmap; // Constructor, getters, and setters omitted for brevity }
To pass an instance of this class through an Intent, you can use a Bundle:
Bundle bundle = new Bundle(); bundle.putSerializable("value", thumbnail); intent.putExtras(bundle);
In the receiving Activity, you can retrieve the data as follows:
Intent intent = this.getIntent(); Bundle bundle = intent.getExtras(); Thumbnail thumbnail = (Thumbnail)bundle.getSerializable("value");
Note that the Bundle.putSerializable() method takes an Object as its argument, so you can pass any object that implements the Serializable interface.
Troubleshooting
If you are not able to pass data through an Intent using Serializable, here are a few things to check:
The above is the detailed content of How to Pass Data Through an Intent Using Serializable in Android?. For more information, please follow other related articles on the PHP Chinese website!