Android transfer object

Source: Internet
Author: User

We know that in Android, bundle or intent can be used to store and transmit data. Sometimes, because of some program needs, we may need to pass a variety of custom objects. It is not enough to pass only simple types of data. However, these objects cannot be directly transmitted between activities. How can this problem be solved?

Method 1: A public class is used as the object transmission intermediary, but the security is poor. The transmission may fail due to the call of multiple classes.
Write the variable as a public static type and set center. A = new in a Activiy.
Obiect () receives object B = center. A in B Activiy, for example:
Public
Class center {
Public static object
A;
}

Method 2: Implement interface serializable
Implement the serializable interface.

Method 3: Implementation interface parcelable
You need to implement the parcelable interface and its method, write the object attribute in the writetoparcel () method, add the public static variable creator, and read the object attribute here.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.