綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[資料] Android 跨進程傳遞對像

[複製連結] 查看: 790|回覆: 1|好評: 0
跳轉到指定樓層
樓主
暗桌之光 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2011-7-19 16:01

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
android 跨進程傳遞對像必須實現Parcelable 「協議」,例如 public class StatusBarIcon 的對象要能夠實現傳遞功能,必須如此寫:
  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */


  15. package com.android.internal.statusbar;
  16. import android.os.Parcel;
  17. import android.os.Parcelable;

  18. /**
  19. * @hide
  20. */

  21. public class StatusBarIcon implements Parcelable {
  22. public String iconPackage;
  23. public int iconId;
  24. public int iconLevel;
  25. public boolean visible = true;
  26. public int number;
  27. private StatusBarIcon() {
  28. }
  29. public StatusBarIcon(String iconPackage, int iconId, int iconLevel) {
  30. this.iconPackage = iconPackage;
  31. this.iconId = iconId;
  32. this.iconLevel = iconLevel;
  33. }
  34. public StatusBarIcon(String iconPackage, int iconId, int iconLevel, int number) {
  35. this.iconPackage = iconPackage;
  36. this.iconId = iconId;
  37. this.iconLevel = iconLevel;
  38. this.number = number;
  39. }
  40. public String toString() {
  41. return "StatusBarIcon(pkg=" + this.iconPackage + " id=0x" + Integer.toHexString(this.iconId)
  42. + " level=" + this.iconLevel + " visible=" + visible+ " num=" + this.number + " )";
  43. }
  44. public StatusBarIcon clone() {
  45. StatusBarIcon that = new StatusBarIcon(this.iconPackage, this.iconId, this.iconLevel);
  46. that.visible = this.visible;
  47. that.number = this.number;
  48. return that;
  49. }


  50. /**
  51. * Unflatten the StatusBarIcon from a parcel.
  52. */
  53. public StatusBarIcon(Parcel in) {
  54. readFromParcel(in);
  55. }
  56. public void readFromParcel(Parcel in) {
  57. this.iconPackage = in.readString();
  58. this.iconId = in.readInt();
  59. this.iconLevel = in.readInt();
  60. this.visible = in.readInt() != 0;
  61. this.number = in.readInt();
  62. }


  63. public void writeToParcel(Parcel out, int flags) {
  64. out.writeString(this.iconPackage);
  65. out.writeInt(this.iconId);
  66. out.writeInt(this.iconLevel);
  67. out.writeInt(this.visible ? 1 : 0);
  68. out.writeInt(this.number);
  69. }


  70. public int describeContents() {
  71. return 0;
  72. }
  73. /**
  74. * Parcelable.Creator that instantiates StatusBarIcon objects
  75. */
  76. public static final Parcelable.Creator<StatusBarIcon> CREATOR
  77. = new Parcelable.Creator<StatusBarIcon>(){
  78. public StatusBarIcon createFromParcel(Parcel parcel)
  79. {
  80. return new StatusBarIcon(parcel);
  81. }
  82. public StatusBarIcon[] newArray(int size)
  83. {
  84. return new StatusBarIcon[size];
  85. }
  86. };
  87. }
複製代碼
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
沙發
Q9Q9Q9Q9Q9 | 收聽TA | 只看該作者
發表於 2011-7-22 10:32
感謝大大分享
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則