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

Vsevolod Kaganovych

02/18/2022, 4:10 PM
I tried to search for the answer but couldn't find it. How can I run some method every time I enter the screen for one time?
b

Big Chungus

02/18/2022, 4:13 PM
LaunchedEffect ir DisposableEffect sound like a good fit, assuming you want something executed each time a composable enters a composition.
a

Ale Stamato

02/18/2022, 4:25 PM
I understood they meant one time and one time only, despite recompositions
b

Big Chungus

02/18/2022, 4:31 PM
And that's what those two effects do. They're not tied to recompositions, but rather their keys. So providing a constant key like Unit would achieve a desired effect.
v

Vsevolod Kaganovych

02/18/2022, 6:14 PM
So assuming I pass there Unit or any immutable value, it will work only once when I enter/get back to that screen?
b

Big Chungus

02/18/2022, 6:15 PM
When your composable enters a composition. Not sure if it's the same as opening a screen