Sequenceablepublic final class CommonEventData extends Object implements Sequenceable
To publish a common event, call the CommonEventData(ohos.aafwk.content.Intent) or
CommonEventData(ohos.aafwk.content.Intent,int,java.lang.String) method to initialize the Intent attribute,
set Action and IntentParams of the common event based on Intent, and then
use the CommonEventManager#publishCommonEvent(CommonEventData) method with CommonEventData
as the input parameter to finish the publishing. To subscribe to a common event, you need to inherit
the class CommonEventSubscriber and override the
CommonEventSubscriber#onReceiveEvent(CommonEventData) callback method. After a common event is received,
CommonEventData stores the received common event object.
SystemCapability.Notification#CESSequenceable.Producer<T>| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static Sequenceable.Producer<CommonEventData> |
PRODUCER |
Creates a
CommonEventData instance from a Parcel. |
| 构造器 | 说明 |
|---|---|
CommonEventData() |
Default constructor used to create an empty
CommonEventData instance. |
CommonEventData(Intent intent) |
Creates a
CommonEventData instance based on the intent parameter to set the content of
a common event. |
CommonEventData(Intent intent,
int code,
String data) |
Creates a
CommonEventData instance based on the parameters intent, code,
and data to set the content of the common event. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
int |
getCode() |
Obtains the result code of a common event.
|
String |
getData() |
Obtains the result data of a common event, which is set by
setData(java.lang.String). |
Intent |
getIntent() |
Obtains the Intent attribute of a common event.
|
boolean |
marshalling(Parcel out) |
Marshals a
CommonEventData object into a Parcel. |
void |
setCode(int code) |
Sets the result code of the common event.
|
void |
setData(String data) |
Sets the result data of a common event.
|
String |
toString() |
Returns a string representation of the object.
|
boolean |
unmarshalling(Parcel in) |
Unmarshals a
CommonEventData object from a Parcel. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waithasFileDescriptorpublic static final Sequenceable.Producer<CommonEventData> PRODUCER
CommonEventData instance from a Parcel.public CommonEventData()
CommonEventData instance.public CommonEventData(Intent intent)
CommonEventData instance based on the intent parameter to set the content of
a common event.intent - Indicates the Intent object used to set the common event content.
This parameter is mandatory. Not allowed to be null, otherwise common event publish fails.Intentpublic CommonEventData(Intent intent, int code, String data)
CommonEventData instance based on the parameters intent, code,
and data to set the content of the common event.intent - Indicates the Intent object used to set the common event content. This parameter is mandatory.code - Indicates the custom result code of the common event. The value of code is generally
-1. You can set it to any int value. This parameter is only applicable to ordered common
events and is optional.data - Indicates the custom result data of the common event. The value of data is generally null.
You can set it to any character string. This parameter is only applicable to ordered common events and is
optional.Intentpublic Intent getIntent()
public void setCode(int code)
code - Indicates the custom result code of the common event. You can set it to any int value. This
parameter is optional.public int getCode()
setCode(int).public void setData(String data)
data - Indicates the custom result data of the common event. You can set it to any character string. This
parameter is optional.public String getData()
setData(java.lang.String).public boolean marshalling(Parcel out)
CommonEventData object into a Parcel.
A process can call the unmarshalling(ohos.utils.Parcel) method to unmarshal
a CommonEventData object from a Parcel to implement
inter-process communication (IPC).
marshalling 在接口中 Sequenceableout - Indicates the Parcel object for marshalling.true if the marshalling is successful; returns false otherwise.public boolean unmarshalling(Parcel in)
CommonEventData object from a Parcel.unmarshalling 在接口中 Sequenceablein - Indicates the Parcel object for unmarshalling.true if the unmarshalling is successful; returns false otherwise.public String toString()
ObjecttoString method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())