Thread
#compose
    Noé Casas

    Noé Casas

    1 year ago
    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

    Ian Lake

    1 year ago
    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
    zhuinden

    zhuinden

    1 year ago
    needs to be parcelable or serializable
    i

    Ian Lake

    1 year ago
    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),
    Andrey Kulikov

    Andrey Kulikov

    1 year ago
    yes, maybe you want to use @Parselize annotation which auto generates parcelable for you
    Noé Casas

    Noé Casas

    1 year ago
    I see, thank you very much!