I have a SparseArray<myObject> and want to save it in a package in the onSaveInstanceState method in my activity and restore it to oncreate . I found the putSparseParcelableArray method to place the SparseArray in the package and did this in the onSaveInstanceState method:
bundle.putSparseParcelableArray("mySparseArray", mySparseArray);
But the eclipse shows this error:
The method putSparseParcelableArray(String, SparseArray<? extends Parcelable>) in the type Bundle is not applicable for the arguments (String, SparseArray<myObject>)
And a quick fix calls the argument mySparsArray before SparseArray<? extends Parcelable> SparseArray<? extends Parcelable> , but if I do this and get in the onCreate method:
mySparseArray = (SparseArray<myObject>) savedInstanceState.getSparseParcelableArray("mySparseArray");
He gets this error:
Cannot cast from SparseArray<Parcelable> to SparseArray<myObject>
If this path is wrong, then what is the solution for placing mySparseArray in a package? Any help is appreciated.
Ehsan source share