Two ways to implement intent additional data in Android _android

Source: Internet
Author: User

The examples in this article describe two implementations of the intent additional data for Android. Share to everyone for your reference. Specifically as follows:

The first method used to bulk add data to intent:

Intent Intent = new Intent ();
Bundle Bundle = new Bundle ();
This class is used to carry data
bundle.putstring ("name", "Lin Yi-chin");
Intent.putextras (bundle);
Additional data is intended to be appended to the intention that the data already in the original intent is not lost, but the data with the same name as the key is replaced 

The second way of writing: This type of writing is equivalent to the above, but this way of writing is to add data into the intent, which is easy to use, and only need to write a small number of code.

Intent Intent = new Intent ();
Intent.putextra ("name", "Lin Yi-chin"); 

Intent provides a Putextra () method after various common type overloads, such as Putextra (string name, String value), Putextra (string name, Long value), in Putextra () The method internally determines whether a bundle object already exists inside the current intent object, and if it does not exist, a new bundle object is created, and subsequent calls to the Putextra () method are stored in the bundle object, followed by intent Putextra ( String name, String value) method code fragment:

public class Intent implements parcelable {
  private Bundle Mextras;
  Public Intent Putextra (string name, String value) {
    if (Mextras = null) {
      Mextras = new Bundle ();
     }
     Mextras.putstring (name, value);
     return this;
   }


I hope this article will help you with your Android program.

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.