Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SparseArray类中的parcelable_Android_Sparse Matrix_Parcelable_Serializable - Fatal编程技术网

Android SparseArray类中的parcelable

Android SparseArray类中的parcelable,android,sparse-matrix,parcelable,serializable,Android,Sparse Matrix,Parcelable,Serializable,我班上有一只名叫test的Sparsarray 测试实现了parcelable,当我通过对象测试时,我希望能够在两个活动之间检索sparsearray,目的如下: Intent intent = new Intent(); intent.putExtra("myObjectTest", myObjectTest); 我看到有WriteSparsarray方法,但它不适用于我的Sparsarray 我当前的代码: public Test(Parcel in) { thi

我班上有一只名叫test的Sparsarray

测试实现了parcelable,当我通过对象测试时,我希望能够在两个活动之间检索sparsearray,目的如下:

    Intent intent = new Intent();
    intent.putExtra("myObjectTest", myObjectTest);
我看到有WriteSparsarray方法,但它不适用于我的Sparsarray

我当前的代码:

public Test(Parcel in) {
     this.id = in.readInt();
     // how to get the sparsearray ?
} 

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(this.id);
    // how can I parse my SparseArray ?
}

您可以使用readSparseArray和writeSparseArray

例如:

public Test(Parcel in) {
     this.id = in.readInt();
     in.readSparseArray(OBJECT_STORED.class.getClassLoader());
} 

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(this.id);
    dest.writeSparseArray(mSparseArray);
}
Bundle bundle = new Bundle();
bundle.putParcelable("myObjectTest", test);
intent.putExtra("myBundleTest",bundle);    
编辑

把包裹放在一个包裹里,然后把这个包裹放进箱子里

例如:

public Test(Parcel in) {
     this.id = in.readInt();
     in.readSparseArray(OBJECT_STORED.class.getClassLoader());
} 

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(this.id);
    dest.writeSparseArray(mSparseArray);
}
Bundle bundle = new Bundle();
bundle.putParcelable("myObjectTest", test);
intent.putExtra("myBundleTest",bundle);    

SparseArray存储的是哪种对象?这是我创建的一个类,它实现了parcelable。不,我几乎尝试过了,但它没有像我说的那样工作。类型Parcel中的WriteSparSearray方法不适用于SparseArray的参数检查此链接,希望它能帮助您: