Android Development--passing objects using intent

Source: Internet
Author: User

There are two ways to pass an object intent:

Way One: Serializable way

Way two: Parcelable Way

Here is not much to introduce, this is a quick start using the tutorial, as for the detailed principles introduced, please see this article http://www.cnblogs.com/kexing/p/8270667.html

We first download a plug-in Android parcelable code generator in Android studio, after the installation is complete restart Android Studio, we create a Java bean class, write the member variables, Directly quickly generate getter and setter, then press Alt+insert, select Pareclable in the Prompt box that appears

Then we can use it ourselves, and in the first activity, TEMP is the object of a book class.

      New Intent (firstactivity.  this, secondactivity. class );        Intent.putextra ("result", temp);        StartActivity (intent);

After that, it is received in the second activity, written on

Book book = Getintent (). Getparcelableextra ("result");

Here the old version needs to add a transformation, the new will be prompted to say is superfluous, to see the situation

Book book = (book) getintent (). Getparcelableextra ("result");

Android Development--passing objects using intent

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.