赞
踩
AIDL可以发送基本数据、String、List、Map和实现Parcable接口的对象
一、创建AIDL文件和Service文件,目录结构如下:
二、AIDL文件
- // IMyAidlInterface.aidl
- package com.mathias.hb.androidbasicknowledge;
-
- // Declare any non-default types here with import statements
- interface IMyAidlInterface {
-
- // 发送基本数据
- int plus(int a, int b);
- int reduce(int a,int b);
-
- // 发送String
- String getString();
-
- // 发送List集合
- List getList();
- }
- package com.mathias.hb.androidbasicknowledge.service;
-
- import android.app.Service;
- import android.content.Intent;
- import android.os.IBinder;
- import android.os.RemoteException;
- import android.util.Log;
-
-
- import com.mathias.hb.androidbasicknowledge.IMyAidlInterface;
- import com.mathias.hb.androidbasicknowledge.bean.Student;
-
- import java.util.ArrayList;
- import java.util.List;
-
- public class MyAIDLService extends Service {
-
- static int binderId = 0;
- List<Integer> list;
- String str = "hello world";
- Student student = new Student("Mathias","men",25);
-
- public MyAIDLService() {
-
- }
-
- @Override
- public void onCreate() {
- super.onCreate();
- Log.v("MyAidlService","onCreate");
-
- list = new ArrayList();
- for (int i = 0;i < 5 ; i++){
- list.add(i);
- }
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- Log.v("MyAidlService","onStartCo
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。