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. Java编程的逻辑 (37) - 泛型 (下) - 细节和局限性

    本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...

  2. linux编译内核make menuconfig报错Unable to find the ncurses libraries解决办法

    在 linux 编译内核时 make menuconfig 报了下面的错误. *** Unable to find the ncurses libraries or the *** required ...

  3. Swagger+IdentityServer4测试授权验证

    1.Bearer授权操作,添加如下代码 services.AddSwaggerGen(options => { options.AddSecurityDefinition("Beare ...

  4. 打FFT时中发现的卡常技巧

    题目:洛谷P1919 A*B Problem 加强版 我的代码完全借鉴boshi,然而他380ms我880ms...于是我通过彻底的卡(chao)常(dai)数(ma)成功优化到了380ms,都是改了 ...

  5. bzoj 1190

    思路:分层dp,因为给的w都是a*(2 ^ b)的形式, 我们将这些物品按b分层, 我们设 dp[ i ][ j ]表示在 第 i 层 容量为(j << i)的最大值, 然后通过层与层之间 ...

  6. Linux性能优化之磁盘优化(三)

    前言 关于本章内容,设计的东西比较多.这里会有关于文件系统.磁盘.CPU等方面的知识,以及涉及到关于这方面的性能排查等. 术语 文件系统通过缓存和缓冲以及异步I/O等手段来缓和磁盘的延时对应用程序的影 ...

  7. php 导出excel文件

    out_excel.php <?phperror_reporting(E_ALL);date_default_timezone_set('Asia/Shanghai');require_once ...

  8. maven打包时包含本地jar

    项目中需要使用maven的打包工具,生成zip压缩包,使用的插件是assembly-plugin.因为一些特殊的原因,需要使用一些本地的jar进行依赖,加载外部jar后编码过程中没有任何问题,但是打包 ...

  9. 【原创】MySQL Can't create a new thread报错分析

    今天有两台服务器都出现了Can't create a new thread报错. [故障处理过程] 故障发生后登录服务器,检查mysql进程正常,但登录mysql报下面错误 ERROR 1135 (H ...

  10. JAVAEE——SpringBoot入门:简介、微服务、环境准备、helloworld与探究、快速构建项目

    一.Spring Boot 入门 1.Spring Boot 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案: 2.微服务 2014,m ...