0

我有一个CustomEvent扩展类java.util.EventObject

public class CustomEvent extends EventObject {
public CustomEvent(Object _src) {
 super(_src);
}
private String name;
public String getName()
 {
  return name;
 }
public void setName(String name)
 {
  this.name = name;
 }
}

我想在我的 Android 应用程序中以这种方式传输此对象:- Service> Notification>Activity

我读到传输对象的理想方法是使用 aParcelable并通过 an 传递该对象,Intent但我不确定是否可以使此类实现Parcelable。如果可以,那么我的writeToParcel(..)readFromParcel(..)方法应该如何实现?

由于java.util.EventObject实现了这个Serializable接口,即使不是,我也不能直接通过ObjectIntent 传递它Parcelable吗?

4

1 回答 1

1

You can pass a Serializable Object via an Inent:

Intent intent = new Intent(...);
intent.putExtra("ser-object", someSerializableObject);

You can then get this value from the Intent using getSerializableExtra(String name) method.

While Parselable is the Android way of passing objects around, support for Serializable is still present.

于 2012-05-22T09:31:54.893 回答