Android Development Aidl using custom objects as parameters or return values

Source: Internet
Author: User

Http://www.pocketdigi.com/20121129/952.html

By default, Aidl supports objects as arguments, but requires the object to implement the Parcelable interface, and the Aidl file should be the same class under the same package, and you need to define a Aidl file for that class separately.
To define a model class:
Englishitem.java:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 6667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611 7118119120121122
Package Com.pocketdigi.english.aidl; import Android.os.parcel;import Android.os.parcelable; import Com.j256.ormlite.field.databasefield;import Com.j256.ormlite.table.databasetable;import Com.pocketdigi.english.utils.constants;import com.pocketdigi.english.utils.des;  @DatabaseTable (tableName = " Listenlist ") public class Englishitem implements parcelable {/** * */private static final long Serialversionuid =-1756522 544697525757L; @DatabaseField (id = true) private int id; @DatabaseFieldprivate string title; @DatabaseFieldprivate String Category: @DatabaseFieldprivate string mp3url; @DatabaseFieldprivate string lrcurl; @DatabaseFieldprivate string Txturl ;  public static final parcelable.creator<englishitem> Creator = new Parcelable.creator<englishitem> ( {Public Englishitem Createfromparcel (Parcel.) {return new Englishitem (in);}  public englishitem[] NewArray (int size) {return new englishitem[size];};  private Englishitem (Parcel in) {Readfromparcel (in);}  public int getId () {return ID;}  public void setId (int id) {this.id = ID;}  public String GetTitle () {return title;}  public void Settitle (String title) {this.title = title;}  public String getcategory () {return category;}  public void Setcategory (String category) {this.category = category;}  public String Getmp3url () {return Des.decodevalue (Constants.des_key, mp3url);}  public void Setmp3url (String mp3url) {this.mp3url = Mp3url;}  public String Getlrcurl () {return Des.decodevalue (Constants.des_key, lrcurl);}  public void Setlrcurl (String lrcurl) {this.lrcurl = Lrcurl;}  public String Gettxturl () {return Des.decodevalue (Constants.des_key, txturl);}  public void Settxturl (String txturl) {this.txturl = Txturl;}   @Overridepublic int describecontents () {//TODO auto-generated method Stubreturn 0;}   @Overridepublic void Writetoparcel (Parcel out, int flag) {//TODO auto-generated method Stubout.writeint (ID); o Ut.writestring (title); OUT.WRItestring (category); out.writestring (Mp3url); out.writestring (Lrcurl); out.writestring (Txturl);} /** * Read * @param in */public void Readfromparcel (Parcel in) {Id=in.readint (); title=in.readstring (); category= In.readstring (); category=in.readstring (); lrcurl=in.readstring (); txturl=in.readstring ();}}

Parcelable.creator is not rare.
Define a englishitem.aidl under the same package:

12
Package com.pocketdigi.english.aidl;parcelable Englishitem;

Finally, call the interface aidl:
Playeraidl.aidl:

123456789101112131415161718192021222324252627
Package com.pocketdigi.english.aidl; Import Com.pocketdigi.english.aidl.EnglishItem; Interface Playeraidl {/*** incoming list **/void putlist (inout list<englishitem> item);/*** play specified audio **/void play (int index); void Pause ();/*** resumes playback after pausing **/void resume ()/*** Delete specified item **/void delete (int position);/*** Stop service **/void stopservice ();}
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.