9

我想通过捆绑将 Runnable 传递给活动,以便在 onCreate 触发时必须运行 runnable。我写了一个实现 Serializable 的类,但它会导致异常:"java.lang.RuntimeException: Parcelable encountered IOException writing serializable object". 我的代码在这里:

package some.company.common;

import java.io.Serializable;

public class SerializedRunnable implements Serializable, Runnable {

    private static final long serialVersionUID = 6641813629033240205L;

    public SerializedRunnable() {
    }

    private Runnable runnable;

    public SerializedRunnable(Runnable runnable) {
        this.runnable = runnable;
    }

    @Override
    public void run() {
        this.runnable.run();
    }

}
4

1 回答 1

0

看起来 Runnable 是不可序列化的。要实现您自己的序列化,您必须readObject自己实现writeObject

在这里检查

于 2012-12-16T08:52:21.060 回答