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. express-partials使用方法

    1.安装express-partials 方法一:运行cmd用npm install express-partials 方法二:在package.json里面的dependencies添加" ...

  2. vs2017 Remote Debugger远程调试目录

    默认目录:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Remote Debugger

  3. shell升级完整记录

    [root@localhost bash-4.3.30]# cat Makefile |grep prefix prefix = /usr/local exec_prefix = ${prefix} ...

  4. Laravel中服务提供者和门面模式

    在laravel中,我们可能需要用到自己添加的类时,可以建立一个文件夹专门存放类文件,也可以使用laravel的服务提供者的方式来使用. 这两者其实区别不大,主要是前者使用的话,会跟业务代码产生依赖, ...

  5. git stash命令使用手册

    修改记录压栈保存: git stash push -u -m "msg" // -u ~ --意思是包含未被跟踪的文件git stash push -m "msg&quo ...

  6. Build OpenJDK9 on macOS Sierra

    1. Get the source code: hg clone http://hg.openjdk.java.net/jdk9/jdk9 jdk9 cd jdk9 sh get_source.sh ...

  7. 【转载】Java是传值还是传引用

    1. 简单类型是按值传递的 Java 方法的参数是简单类型的时候,是按值传递的 (pass by value).这一点我们可以通过一个简单的例子来说明: /* 例 1 */ /** * @(#) Te ...

  8. 000 Jquery的Hello World程序

    1.介绍Jquery 2.简介 3.新建一个静态项目,并粘贴jquery库 4.程序 <!DOCTYPE html> <html> <head> <meta ...

  9. Could not resolve com.android.support:appcompat-v7:28.0.0 错误处理

      20181008 总是出现错误 Could not resolve com.android.support:appcompat-v7:28.0.0 1.先是怀疑前些天降级了jdk 1.8 ,所以重 ...

  10. Spring框架学习01——使用IDEA开发Spring程序

    1.创建项目 点击“Create New Project”,新建项目 选择Maven项目 项目配置 使用本地安装的Maven 一直点击Next,最后点击完成当控制台中出现“BUILD SUCCESS” ...