'How to check in Android compose whether an application was restored after the process termination?

I need to initialize a ViewModel once user opened a screen. In precompose times I can check whether savedInstanceState != null. Is there any replacement for such check in compose?

I came up with two options:

  1. To call initialization code in rememberSaveable:
rememberSaveable {
    viewModel.init()
    true // We can't return Unit here, because the result should be saved in Bundle
}
  1. To save a flag in SavedStateHandle

Are there any better options?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source