androidx.core.os.ParcelableCompat 已弃用

应该使用什么,因为该类已被弃用。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];

        }


    });


qq_遁去的一_1
浏览 199回答 2
2回答

慕婉清6462132

Android 开发文档要求您直接从 API v26.1.0 开始使用Parcelable.ClassLoaderCreator 。public static interface Parcelable.ClassLoaderCreator implements Creator<T>&nbsp;android.os.Parcelable.ClassLoaderCreator<T>

PIPIONE

来自Android 开发者文档ParcelableCompat 类在 API 级别 26.1.0 中已弃用。直接使用Parcelable.ClassLoaderCreator。所以改变你的代码public static final Parcelable.Creator<SavedState> CREATOR&nbsp; &nbsp; &nbsp; &nbsp; = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public SavedState createFromParcel(Parcel in, ClassLoader loader) {&nbsp; &nbsp; &nbsp; &nbsp; return new SavedState(in, loader);&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; public SavedState[] newArray(int size) {&nbsp; &nbsp; &nbsp; &nbsp; return new SavedState[size];&nbsp; &nbsp; }});至public static final Parcelable.ClassLoaderCreator<SavedState> CREATOR&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; = new Parcelable.ClassLoaderCreator<SavedState>() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public SavedState createFromParcel(Parcel source) {&nbsp; &nbsp; &nbsp; &nbsp; return createFromParcel(source, null);&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; @Override&nbsp; &nbsp; public SavedState createFromParcel(Parcel source, ClassLoader loader) {&nbsp; &nbsp; &nbsp; &nbsp; return new SavedState(source, loader);&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; @Override&nbsp; &nbsp; public SavedState[] newArray(int size) {&nbsp; &nbsp; &nbsp; &nbsp; return new SavedState[size];&nbsp; &nbsp; }};
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java