2

In Fragment lifecycle, we have onCreateView and onViewCreated.

What is the correct alternative for these lifecycle methods in jetpack compose?

Should I use LaunchedEffect(true) for both or are there different ways to handle these lifecycle callbacks?

Edit 1.
The main focus of this question is to understand if there is any difference in handling those two fragment lifecycle methods.

The taged question does not explicitly answer my question.
Philip's comment below does.

Abhimanyu
  • 11,351
  • 7
  • 51
  • 121
  • Does this answer your question? [How are Android activities handled with Jetpack Compose and Compose Navigation?](https://stackoverflow.com/questions/68962458/how-are-android-activities-handled-with-jetpack-compose-and-compose-navigation) – Phil Dukhov Aug 29 '21 at 08:20
  • 1
    Shortly, yes, `LaunchedEffect` is the compose way of doing that. In declarative way there's no need to listen `onViewCreated`, because you can declare all needed composables with relationships without waiting it to be "created" – Phil Dukhov Aug 29 '21 at 08:24
  • Your last comment was what I was looking for. To confirm if there is any difference between handling these two methods. Thanks. BTW - Your answers on jetpack compose questions help me a lot. – Abhimanyu Aug 29 '21 at 08:25

1 Answers1

3

In the declarative way there's no need to listen onViewCreated, because you can declare all needed composables with relationships without waiting it to be "created" or rendered.

And yes, LaunchedEffect is the compose way of doing that.

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220