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. numpy和pandas简单使用

    numpy和pandas简单使用 import numpy as np import pandas as pd 一维数据分析 numpy中使用array, pandas中使用series numpy一 ...

  2. MySQL保存或更新 saveOrUpdate

    1. 引子 在项目开发过程中,有一些数据在写入时候,若已经存在,则覆盖即可.这样可以防止多次重复写入唯一键冲突报错.下面先给出两个MyBatis配置文件中使用saveOrUpdate的示例 <! ...

  3. maven待整理

    http://blog.csdn.net/column/details/yuguiyang-maven.html?&page=2

  4. java 多重继承

    接口不仅仅只是一种更纯粹形式的抽象类,它的目标比这更高,因为接口是根本没有任何具体实现的--也就是说,没有任何与接口相关的存储,因此也就无法阻止多个接口的组合, 在导出类中,不强制要求必须有一个抽象的 ...

  5. Codeforces 601C Kleofáš and the n-thlon 概率dp

    Kleofáš and the n-thlon 我们可以用dp算出比当前这个人得分少的概率, 然后人数乘概率就好啦. dp[ i ][ j ]表示进行了 i 轮 得分为 j 的概率, 因为每个人都是独 ...

  6. Codeforces Round #475 (Div. 2) C - Alternating Sum

    等比数列求和一定要分类讨论!!!!!!!!!!!! #include<bits/stdc++.h> #define LL long long #define fi first #defin ...

  7. Github如何撤销提交并清除痕迹

    1.在命令行工具中进入项目目录 cd /Users/mac.manon/workspace/QuickCodes 2.sudo git reset --hard HEAD~4 根据提示输入本系统登录密 ...

  8. 浅谈Spring的AOP实现-代理机制

    说起Spring的AOP(Aspect-Oriented Programming)面向切面编程大家都很熟悉(Spring不是这次博文的重点),但是我先提出几个问题,看看同学们是否了解,如果了解的话可以 ...

  9. IO写 PrintWriter

    private static final String FILENAME = "c:\\temp\\out.txt"; PrintWriter pw = null; try { p ...

  10. 数据包注入重放工具aireplay-ng

    数据包注入重放工具aireplay-ng   aireplay-ng是aircrack-ng组件包的一个工具.它可以注入和重放数据帧,用于后期的WEP.WPA-PSK破解.它提供九种攻击模式,包括死亡 ...