Hi, I'm using `rememberSaveable {}` on a custom cl...
# compose
a
Hi, I'm using
rememberSaveable {}
on a custom class that implements
Parcelable
. This saves and restores the object on screen rotation perfectly. All the warning messages, however, tell me that this should not work. Can you help me understand the warning messages? And help me understand if I'm doing something wrong? Code and warnings in 🧵
Copy code
@Parcelize
class MyState() : Parcelable {
  private var _inputText by mutableStateOf("")
  val inputText by derivedStateOf { _inputText }
  val inputTextChange = { s:String ->
    _inputText = s
  }
}
Copy code
rememberSaveable { MyState() }
Copy code
The primary constructor is empty, no data will be serialized to 'Parcel'
And this x3
Copy code
Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning
So, the error message suggest nothing will be serialised. Yet, when I rotate the screen, the state is restored and my UI has the correct text (unlike if I just use
remember {}
)
p
On config change nothing is really parceled, it's just put in a map and read from it.
You need to kill the process for the parceling to happen
t
@Paul Woitaschek So the proper way would be to use a custom
Saver
?
p
Either that or properly implement parcelable
🆗 1
Write the parcel yourself before using the annotation magic to understand how that works and what the compiler plugin is doing