[经验分享]Android中AIDL实现(跨进程通信.pdfVIP

  • 0
  • 0
  • 约9.47千字
  • 约 10页
  • 2021-11-14 发布于山西
  • 举报

[经验分享]Android中AIDL实现(跨进程通信.pdf

[经验分享 ] Android 中 AIDL 实现(跨进程通信,有源码) 本帖最后由 Mr jing 于 2011-5-3 15:46 编辑 一. 概述: 跨进程通信( AIDL ),主要实现进程(应用)间数据共享功能。 二. 实现流程: 1. 服务器端实现: (1 )目录结构,如下图: (2 )实现 *.aidl 文件: A. IAIDLService.aidl 实现: view plaincopy to clipboardprint? 1. package com.focus.aidl; 2. 3. import com.focus.aidl.Person; 4. 5. interface IAIDLService { 6. 7. String getName(); 8. 9. Person getPerson(); 10. 11. } B. Person.aidl 实现: view plaincopy to clipboardprint? 1. parcelable Person; (3 )进程间传递对象必需实现 Parcelable 或 Serializable 接口,下面是被传递的 Person 对象实现: view plaincopy to clipboardprint? 1. package com.focus.aidl; 2. 3. import android.os.Parcel; 4. import android.os.Parcelable; 5. 6. public class Person implements Parcelable { 7. 8. private String name; 9. 10. private int age; 11. 12. public Person() { 13. 14. } 15. 16. public Person(Parcel source) { 17. name = source.readString(); 18. age = source.readInt(); 19. } 20. 21. public String getName() { 22. return name; 23. } 24. 25. public void setName(String name) { 26. = name; 27. } 28. 29. public int getAge() { 30. return age; 31. } 32. 33. public void setAge(int age) { 34. this.age = age; 35. } 36. 37. public int describeContents() { 38. return 0; 39. } 40. 41. public void writeToParcel(Parcel dest, int flags) { 42. dest.writeString(name); 43. dest.writeInt(age); 44. } 45. 46. public static final Parcelable.Creator;Person CREATOR = new Creator;Person() { 47. public Pers

文档评论(0)

1亿VIP精品文档

相关文档