Home > Java > javaTutorial > How to Pass a Serializable List of Objects via Intent in Android?

How to Pass a Serializable List of Objects via Intent in Android?

Barbara Streisand
Release: 2024-12-04 02:35:11
Original
243 people have browsed it

How to Pass a Serializable List of Objects via Intent in Android?

Passing Objects with Serializable

In this query, the user is encountering difficulties in transferring a serializable class via an intent. Despite implementing Serializable, the operation remains unsuccessful.

The class involved, Thumbnail, contains attributes and methods for managing labels and bitmaps. The user attempted to send a list of these Thumbnail objects via intent, but without success.

To resolve this issue, it is not necessary to use Parcelable. Instead, the user can pass the serializable list using a Bundle.Serializable within the intent.

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

On the receiving end, within the SomeClass Activity:

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

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

This approach enables successful data transfer of the Thumbnail object list via intent using Serializable.

The above is the detailed content of How to Pass a Serializable List of Objects via Intent in Android?. 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