我想通过捆绑将 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();
}
}