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

默认,AIDL支持对象作参数,但需要该对象实现Parcelable接口,且aidl文件应该是该类在同一包下,需要单独给该类定义一个aidl文件.
定义模型类:
EnglishItem.java:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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 = -1756522544697525757L;
@DatabaseField(id = true)
private int id;
@DatabaseField
private String title;
@DatabaseField
private String category;
@DatabaseField
private String mp3url;
@DatabaseField
private String lrcurl;
@DatabaseField
private String txturl;
 
public static final Parcelable.Creator<EnglishItem> CREATOR = new Parcelable.Creator<EnglishItem>() {
public EnglishItem createFromParcel(Parcel in) {
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;
}
 
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
 
@Override
public void writeToParcel(Parcel out, int flag) {
// TODO Auto-generated method stub
out.writeInt(id);
out.writeString(title);
out.writeString(category);
out.writeString(mp3url);
out.writeString(lrcurl);
out.writeString(txturl);
}
/**
* 读
* @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不可少。
同包下定义一个EnglishItem.aidl:

1
2
package com.pocketdigi.english.aidl;
parcelable EnglishItem;

最后是调用接口aidl:
PlayerAidl.aidl:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.pocketdigi.english.aidl;
 
import com.pocketdigi.english.aidl.EnglishItem;
 
interface PlayerAidl {
/**
*传入列表
**/
void putList(inout List<EnglishItem> item);
/**
*播放指定音频
**/
void play(int index);
void pause();
/**
*暂停后恢复播放
**/
void resume();
/**
*删除指定项
**/
void delete(int position);
/**
*停止服务
**/
void stopService();
}

Android开发 AIDL使用自定义对象作参数或返回值的更多相关文章

  1. Android JNI 自定义对象为参数和返回值

    ndroid JNI 提供了很强大的支持,不仅可以采用基本类型做为参数和返回值,同时也支持自定义对象做为参数和返回值,以下举例说明. 一.定义作为输入和返回的自定义类 (仅提供两个简单类型和一个打印函 ...

  2. 论DATASNAP远程方法支持自定义对象作参数

    论DATASNAP远程方法支持自定义对象作参数 DATASNAP远程方法已经可以支持自定义对象作参数,这是非常方便的功能. 1)自定义对象 type TMyInfo = class(TObject) ...

  3. STL算法设计理念 - 函数对象和函数对象当参数和返回值

    函数对象: 重载函数调用操作符的类,其对象常称为函数对象(function object),即它们是行为类似函数的对象.一个类对象,表现出一个函数的特征,就是通过"对象名+(参数列表)&qu ...

  4. Python rich comparisons 自定义对象比较过程和返回值

    Classes wishing to support the rich comparison mechanisms must add one or more of the following new ...

  5. day09-Python运维开发基础(函数收集参数、命名关键字参数与返回值、函数名的特殊使用及 全局/局部变量详解)

    1. 函数收集参数.命名关键字参数与返回值.函数名的特殊使用 # ### 默认形参 和 关键字实参 # 默认形参和 关键字实参 在写法上是一样 # 函数的定义处 """默 ...

  6. 匿名对象作为方法的参数和返回值与Random概念和基本使用

    应用场景 1. 创建匿名对象直接调用方法,没有变量名. new Scanner(System.in).nextInt(); 2. 一旦调用两次方法,就是创建了两个对象,造成浪费,请看如下代码. new ...

  7. Java开发学习(十八)----AOP通知获取数据(参数、返回值、异常)

    前面的博客我们写AOP仅仅是在原始方法前后追加一些操作,接下来我们要说说AOP中数据相关的内容,我们将从获取参数.获取返回值和获取异常三个方面来研究切入点的相关信息. 前面我们介绍通知类型的时候总共讲 ...

  8. java Servlet+mysql 调用带有输入参数和返回值的存储过程(原创)

    这个数据访问的功能,我在.NET+Mysql .NET+Sqlserver  PHP+Mysql上都实现过,并且都发布在了我博客园里面,因为我觉得这个功能实在是太重要,会让你少写很多SQL语句不说,还 ...

  9. Java基础学习笔记十二 类、抽象类、接口作为方法参数和返回值以及常用API

    不同修饰符使用细节 常用来修饰类.方法.变量的修饰符 public 权限修饰符,公共访问, 类,方法,成员变量 protected 权限修饰符,受保护访问, 方法,成员变量 默认什么也不写 也是一种权 ...

随机推荐

  1. 关于tp5 的验证码遇到的一些问题

    问题1: 网上大部分给的安装包是: composer require topthink/think-captcha 但是会提示你下载失败说要你回复*****的原始数据啥的 那可能是因为你的安装环境版本 ...

  2. java 异常说明

    异常说明使用了附加的关键字 throws ,后面接一个所有潜在异常类型的列表,方便客户端程序员查看. public static void main(String[] args) throws Nul ...

  3. idea 从数据库快速生成Spring Data JPA实体类

    第一步,调出 Persistence 窗口. File—>Project Structure—>model—> + —>JPA 第二步:打开 Persistence窗口 配置 ...

  4. MySQL的架构模型

    看到大牛用户DB架构部的Keithlan<数据库性能优化之查询优化>,在学习过程发现很多不错的东西,就把它保存下来,分享给大家,因为作者说了一句很经典的话:“if you want to ...

  5. Android开源库集合(工具)

    图片加载框架: Glide https://github.com/bumptech/glide Android-Universal-Image-Loader https://github.com/no ...

  6. ubuntu下hadoop,spark配置

    转载来自:http://www.cnblogs.com/spark-china/p/3941878.html 在VMWare 中准备第二.第三台运行Ubuntu系统的机器:   在VMWare中构建第 ...

  7. Wireshark网络分析就这么简单

    tcpdump抓包命令: root#tcpdump -I eth0 -s 80 -w /tmp/tcpdump.cap 注:其中80表示,只抓每个包的前80个字节. 抓包时就筛选自己需要的包: Wir ...

  8. org.apache.maven.archiver.MavenArchiver.getManifest错误

    eclipse导入新的maven项目时,pom.xml第一行报错: org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.mav ...

  9. 001.KVM介绍

    KVM介绍可参考: http://liqingbiao.blog.51cto.com/3044896/1740516 http://koumm.blog.51cto.com/703525/128879 ...

  10. django views视图

    视图函数简称视图,本质上是一个简单的python函数,它接受web请求并且返回web响应:响应的内容可以是HTML网页.重定向.404错误.XML文档或图像等任何东西,但是,无论视图本身是个什么处理逻 ...