首先,我检查了这个答案。
我想做的是扩展Location
调用它的类,LocationPlus
它有一些成员变量。我想要实现的功能是将LocationPlus
类的对象从一个活动传递到另一个活动。
这是我的CREATOR
public static final Parcelable.Creator<LocationPlus> CREATOR = new Parcelable.Creator<LocationPlus>() {
@Override
public LocationPlus createFromParcel(Parcel source) {
return new LocationPlus(source);
}
@Override
public LocationPlus[] newArray(int size) {
return new LocationPlus[size];
}
};
我面临的问题是这个错误
Implicit super constructor Location() is undefined. Must explicitly invoke another constructor
尝试编写构造函数时
public LocationPlus(Parcel in) {
有人在评论中要求我发布 LocationPlus 课程,所以在这里
public class LocationPlus extends Location{
private int mBattery = -1;
public LocationPlus(String locationName) {
super(locationName);
}
public LocationPlus(Location location) {
super(location);
}
public int getmBattery() {
return mBattery;
}
public void setmBattery(int mBattery) {
this.mBattery = mBattery;
}
@Override
public int describeContents() {
return 0;
}
public static final Parcelable.Creator<LocationPlus> CREATOR = new Parcelable.Creator<LocationPlus>() {
@Override
public LocationPlus createFromParcel(Parcel source) {
return new LocationPlus(source);
}
@Override
public LocationPlus[] newArray(int size) {
return new LocationPlus[size];
}
};
@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeInt(mBattery);
}
public LocationPlus(Parcel in) {
mBattery =in.readInt();
}
}