I am getting an exception related to `SaveableStat...
# compose
n
I am getting an exception related to
SaveableStateProvider
that says
java.lang.IllegalArgumentException: Type of the key XXXX is not supported. On Android you can only use types which can be stored inside the Bundle.
. What does it mean that a type can be stored inside the Bundle? Here,
XXXX
is a mere sealed class, nothing exotic.
i
Bundle (and
BaseBundle
, the class it extends) has a bunch of specific types it supports - you'll note the
putString
,
putParcelable
, etc. methods on the class: https://developer.android.com/reference/android/os/Bundle
One of the parameters
rememberSaveable
takes is a
Saver
that lets you translate your mere sealed class into something that can be persisted across process death/recreation in a Bundle: https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/package-summary#remembersaveable
z
needs to be parcelable or serializable
i
Copy code
private static final Class[] ACCEPTABLE_CLASSES = new Class[]{
            //baseBundle
            boolean.class,
            boolean[].class,
            double.class,
            double[].class,
            int.class,
            int[].class,
            long.class,
            long[].class,
            String.class,
            String[].class,
            //bundle
            Binder.class,
            Bundle.class,
            byte.class,
            byte[].class,
            char.class,
            char[].class,
            CharSequence.class,
            CharSequence[].class,
            // type erasure ¯\_(ツ)_/¯, we won't eagerly check elements contents
            ArrayList.class,
            float.class,
            float[].class,
            Parcelable.class,
            Parcelable[].class,
            Serializable.class,
            short.class,
            short[].class,
            SparseArray.class,
            (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? Size.class : int.class),
            (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? SizeF.class : int.class),
a
yes, maybe you want to use @Parselize annotation which auto generates parcelable for you
n
I see, thank you very much!
453 Views