Using intent to transmit data in Android, if you pass a class, implement the Class Parcelable interface

Source: Internet
Author: User

Parcelable, memory units, used across processes, or intent when passing objects.
Android uses intent to transmit data, and if it is passed an object, it implements the Parcelable interface instead of serializing the object.
/*** Pre-registration attendance leader back to pre-registration page Javabean * Created by COCO on 2017/3/4.*/ Public classGovernmenttakeleaderinfoImplementsparcelable{//parcelable, memory units, used across processes, or intent when passing objects    PrivateString name; PrivateString Leaderid; //The default constructor is to add     PublicGovernmenttakeleaderinfo () {}; protectedGovernmenttakeleaderinfo (Parcel in) {name=in.readstring (); Leaderid=in.readstring (); }     Public Static FinalCreator<governmenttakeleaderinfo> Creator =NewCreator<governmenttakeleaderinfo>() {@Override Publicgovernmenttakeleaderinfo Createfromparcel (Parcel in) {return NewGovernmenttakeleaderinfo (in); } @Override PublicGovernmenttakeleaderinfo[] NewArray (intsize) {            return NewGovernmenttakeleaderinfo[size];    }    };  PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     PublicString Getleaderid () {returnLeaderid; }     Public voidSetleaderid (String leaderid) { This. Leaderid =Leaderid; } @Override Public intdescribecontents () {return0; } @Override Public voidWritetoparcel (Parcel dest,intflags)        {dest.writestring (name);    Dest.writestring (Leaderid); }}

The above is the data to be passed with intent.

The Parcelablearraylistextra correlation method is called when passing with intent. For example, when the data is returned:

Intent Intent = getintent () Intent.putparcelablearraylistextra ("Data_return", data); // Use Setresult (RESULT_OK, intent) for cross-process use, or for intent passing objects ;

At the time of receiving the data:

Using intent to transmit data in Android, if you pass a class, implement the Class Parcelable interface

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.