Noé Casas
03/17/2021, 8:15 PMSaveableStateProvider
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.Ian Lake
03/17/2021, 8:51 PMBaseBundle
, 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/BundleIan Lake
03/17/2021, 8:52 PMrememberSaveable
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#remembersaveablezhuinden
03/17/2021, 9:17 PMIan Lake
03/17/2021, 9:25 PMSavedStateHandle
(which has the same limitations): https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:lifecycl[…]/src/main/java/androidx/lifecycle/SavedStateHandle.java;l=376Ian Lake
03/17/2021, 9:25 PMprivate 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
03/17/2021, 11:30 PMNoé Casas
03/18/2021, 8:14 AM