Android Intent transmits object, list (object), list (Map (String, Object ))

Source: Internet
Author: User

?? Android uses Intent to pass the object, list, List , Object>

 

Method 1:
If you simply pass the List Or List Then you can directly use

Java code

Intent. putStringArrayListExtra (name, value)

Intent. putIntegerArrayListExtra (name, value)


Method 2:
If List is passed , You can convert list to Serializable type, and then use
Java code putExtras (key, (Serializable) list)
Method passed, used for acceptance
Java code (List ) GetIntent (). getSerializable (key)
The List can be accepted. Data

But remember that your YourObject class must implement the Serializable interface.

Method 3:
One is
Java code Bundle. putSerializable (Key, Object );
The other is
Java code Bundle. putParcelable (Key, Object );
Of course, these objects have certain conditions. The former implements the Serializable interface, while the latter implements the Parcelable interface.


Method 4:
It is inconvenient to use intent to transmit data. We can write a global data in the application.

1. Create a subclass of your own android. app. Application
2. Declare this class in manifest,
3. In this case, android creates a globally available instance. You can use Context. getApplicationContext () to obtain the instance anywhere else, and then obtain the status (variable ).

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.