gpt4 book ai didi

java - androidx.core.os.ParcelableCompat 已弃用

转载 作者:行者123 更新时间:2023-11-29 08:24:09 25 4
gpt4 key购买 nike

应该使用什么,因为该类已被弃用。 ParcelableCompat 已弃用,newCreator() 已弃用,ParcelableComparCreatorCallbacks<> 已弃用。谢谢!

public static final Parcelable.Creator<SavedState> CREATOR
= ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {

@Override
public SavedState createFromParcel(Parcel in, ClassLoader loader) {
return new SavedState(in, loader);
}

@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}

});

最佳答案

来自 Android Developer文档

ParcelableCompat class was deprecated in API level 26.1.0.

Use Parcelable.ClassLoaderCreator directly.

所以改变你的代码

public static final Parcelable.Creator<SavedState> CREATOR
= ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {

@Override
public SavedState createFromParcel(Parcel in, ClassLoader loader) {
return new SavedState(in, loader);
}

@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}

});

public static final Parcelable.ClassLoaderCreator<SavedState> CREATOR 
= new Parcelable.ClassLoaderCreator<SavedState>() {

@Override
public SavedState createFromParcel(Parcel source) {
return createFromParcel(source, null);
}

@Override
public SavedState createFromParcel(Parcel source, ClassLoader loader) {
return new SavedState(source, loader);
}

@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};

关于java - androidx.core.os.ParcelableCompat 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54809618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com