鴻蒙OS Sequenceable

2022-08-16 16:37 更新

Sequenceable

  1. public interface Sequenceable

在進(jìn)程間通信 (IPC) 期間將類的對象寫入 Parcel 并從 Parcel 中恢復(fù)它們。

只有在類繼承自 Sequenceable 并實(shí)現(xiàn) Sequenceable 中提供的編組和解組方法后,才能在 IPC 期間完成此操作。 如果類有一個(gè)final成員變量,其值不能通過調(diào)用unmarshalling來改變,你還必須實(shí)現(xiàn)Sequenceable.Producer中的createFromParcel方法。

示例代碼:

  1. public class Example implements Sequenceable {
  2. private int number;
  3. private String name;
  4. public boolean marshalling(Parcel out) {
  5. return out.writeInt(number) && out.writeString(name);
  6. }
  7. public boolean unmarshalling(Parcel in) {
  8. this.number = in.readInt();
  9. this.name = in.readString();
  10. return true;
  11. }
  12. public static final Sequenceable.Producer
  13. PRODUCER = new Sequenceable.Producer
  14. () {
  15. public Example createFromParcel(Parcel in) {
  16. // Initialize an instance first, then do customized unmarshlling.
  17. Example instance = new Example();
  18. instance.unmarshalling(in);
  19. return instance;
  20. }
  21. };
  22. }

嵌套類摘要

修飾符和類型 接口 描述
static interface Sequenceable.ProducerT 從 Parcel 創(chuàng)建一個(gè) Sequenceable 實(shí)例。

方法總結(jié)

修飾符和類型 方法 描述
default boolean hasFileDescriptor() 檢查此 Sequenceable 的實(shí)現(xiàn)類是否包含 FileDescriptor 對象數(shù)據(jù)。
boolean marshalling(Parcel out) 將此 Sequenceable 對象編組為 Parcel。
boolean unmarshalling(Parcel in) 從 Parcel 中解組此 Sequenceable 對象。

方法詳情

hasFileDescriptor

default boolean hasFileDescriptor()

檢查此 Sequenceable 的實(shí)現(xiàn)類是否包含 FileDescriptor 對象數(shù)據(jù)。

如果自定義 Sequenceable 類包含任何 FileDescriptor 數(shù)據(jù),則應(yīng)覆蓋此方法。 此方法默認(rèn)返回 false。

返回:

如果它包含 FileDescriptor 數(shù)據(jù),則返回 true; 否則返回 false。

marshalling

boolean marshalling(Parcel out)

將此 Sequenceable 對象編組為 Parcel。

參數(shù):

參數(shù)名稱 參數(shù)描述
out 指示將 Sequenceable 對象編組到的 Parcel 對象。

返回:

如果編組成功,則返回 true; 否則返回 false。

Throws:

Throw名稱 Throw描述
ParcelException 如果操作失敗,則拋出此異常。

unmarshalling

boolean unmarshalling(Parcel in)

從 Parcel 中解組此 Sequenceable 對象。

參數(shù):

參數(shù)名稱 參數(shù)描述
in 指示已將 Sequenceable 對象編組到的 Parcel 對象。

返回:

如果解組成功,則返回 true; 否則返回 false。

Throws:

Throw名稱 Throw描述
ParcelException 如果操作失敗,則拋出此異常。
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號