Parcelable在子类中实现的方法

简介:

转自:http://stackoverflow.com/questions/4049627/parcelable-and-inheritance-in-android

public abstract class A implements Parcelable {
    private int a;

    protected A(int a) {
        this.a = a;
    }

    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(a);
    }

    protected A(Parcel in) {
        a = in.readInt();
    }
}

public class B extends A {
    private int b;

    public B(int a, int b) {
        super(a);
        this.b = b;
    }

    public static final Parcelable.Creator<B> CREATOR = new Parcelable.Creator<B>() {
        public B createFromParcel(Parcel in) {
            return new B(in);
        }

        public B[] newArray(int size) {
            return new B[size];
        }
    };

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel out, int flags) {
        super.writeToParcel(out, flags);
        out.writeInt(b);
    }

    private B(Parcel in) {
        super(in);
        b = in.readInt();
    }
}


相关文章
|
9月前
|
Java Android开发
Android 中通过Intent传递类对象,通过实现Serializable和Parcelable接口两种方式传递对象
Android 中通过Intent传递类对象,通过实现Serializable和Parcelable接口两种方式传递对象
81 1
JAVA中子类使用super.getClass()方法
JAVA中子类使用super.getClass()方法
|
Java C语言
Java继承——super关键字
Java继承——super关键字
110 0
|
Java C语言
Java继承——方法重写
Java继承——方法重写
94 0
|
前端开发 JavaScript
class-使用extends实现子类继承父类
class-使用extends实现子类继承父类
类的父类object的一些属性、方法
# class Test: # """文档字符串""" # name = 'scolia' # # print(Test.__doc__) # 提醒一下,函数是help(),实例也可以访问,但是子类并不会继承父类的文档字符串 # print(Test.
812 0