Home > Java > javaTutorial > How to Properly Pass Serializable Data Between Android Activities?

How to Properly Pass Serializable Data Between Android Activities?

Patricia Arquette
Release: 2024-12-23 21:37:11
Original
675 people have browsed it

How to Properly Pass Serializable Data Between Android Activities?

Passing Data through Intent Using Serializable

Implement serializable to transfer data between Android components. However, if your implementation does not work despite marking your class as serializable, consider the following:

Ensure Proper Serializable Implementation

Your Thumbnail class should correctly implement the Serializable interface with a serialVersionUID. Ensure that all fields in the class are either transient or serializable.

Use Bundle.Serializable for Data Transfer

Instead of directly putting the serializable list into the intent, use Bundle.Serializable to pass it:

Bundle bundle = new Bundle();
bundle.putSerializable("value", all_thumbs);
intent.putExtras(bundle);
Copy after login

Retrieve Serializable Data in Receiving Activity

In the receiving activity, retrieve the serializable list using Bundle:

Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();

List<Thumbnail> thumbs =
               (List<Thumbnail>)bundle.getSerializable("value");
Copy after login

The above is the detailed content of How to Properly Pass Serializable Data Between Android Activities?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template