https://kotlinlang.org logo
#compose
Title
# compose
a

adjpd

01/29/2022, 4:18 PM
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

Paul Woitaschek

01/29/2022, 8:24 PM
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

theapache64

01/29/2022, 8:54 PM
@Paul Woitaschek So the proper way would be to use a custom
Saver
?
p

Paul Woitaschek

01/29/2022, 8:58 PM
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
4 Views