0

How can SparseArray be stored in a bundle ?

public void onSaveInstanceState(Bundle savedState) {
    // ...
    SparseArray<Double> values = mAdapter.getValues();
    savedState.putSparseParcelableArray(values);

the code above results in compilation error that says

"SparseArray< ? extends Parcelable > in Bundle cannot be applied to SparseArray< Double >".

How can it be solved ?

insane.bot
  • 193
  • 1
  • 2
  • 11

2 Answers2

2

As per the docs SparseArray<? extends Parcelable> value) mean The class and it's sub type is allowed but Double does not implements Parcelable so you cannot use it with bundle persistence though you can have your customize bean class object implements parcelable

Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
0

for saving the SparseArray, put this data in the list and save that list the outState bundle.

And in onRestoreInstanceState, retrieve the list and convert it to the SparseArray again.

for detailed explaination

akshay_shahane
  • 4,423
  • 2
  • 17
  • 30