Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragment on create view and on view created alternative in jetpack compose?

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.

like image 911
Abhimanyu Avatar asked Dec 05 '25 13:12

Abhimanyu


1 Answers

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.

like image 185
Philip Dukhov Avatar answered Dec 08 '25 02:12

Philip Dukhov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!