Closed stevdza-san closed 2 months ago
what is the solution?
It was necessary to implement Serializable. Does not work with Parcelable
import java.io.Serializable
data class ValidateCodeParameters(
val authenticator: String = "",
val type: String = ""
): Serializable
It will work with Parcelable if you make the Screen itself Parcelable as well
@Syer10 How can I make the screen parcelable?
The normal way https://developer.android.com/kotlin/parcelize
Example of operation, using Parcelable
@Parcelize
data class ValidateCodeParameters(
val authenticator: String = "",
val type: String = ""
) : Parcelable
@Parcelize
class ValidateCodeScreen(
private val parameters: ValidateCodeParameters
) : Screen, Parcelable {
@Composable
override fun Content() {
val viewModel = hiltViewModel<ValidateCodeViewModel>()
val state by viewModel.state.collectAsState()
ValidateCodeScreenView(
parameters = parameters,
state = state,
action = viewModel::submitAction
)
}
}
Id do have a simple Home/Details screen scenario. A Details screen takes an argument/parameter, that I'm passing from a Home screen. It's a custom object that I'm passing. When I do open the Details screen and pass the argument, I click home button on my smartphone to go outside of the app, and put the app in the background, however as soon as I do that I get the exception: Caused by: java.io.NotSerializableException: domain.quiz.Quiz
Which means when I go back to my app, the app will restart and the splash screen will show up again. The state will not be saved. Any solutions?