我想通过bundle将Runnable传递给一个activity,这样runnable必须在onCreate触发时运行。我编写了一个实现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();
}
}