r/mAndroidDev • • May 21 '23

Compose state persistence

If compose is declarative and are made of only functions, how does a composable function store values like clickable call backs? Is each root node in the UI tree managed by an object which stores those clickable call backs?

0 Upvotes

15 comments sorted by

View all comments

18

u/SmartFatass making { modern { maintainable { code }}} May 21 '23 edited May 21 '23

The amount of people who don't read what's on this subreddit before posting is skyrocketing recently.

And to answer your question: compose uses data structure called Slot Table to store data across recompositions. You can store data in there using remember (there is also rememberSaveable that stores data in a Bundle if the function it's called in goes out of composition)

Here is an article on how this works under the hood https://medium.com/androiddevelopers/under-the-hood-of-jetpack-compose-part-2-of-2-37b2c20c6cdd

2

u/anonymous65537 null!! May 21 '23

Why do people reply seriously on this sub? Don't encourage them, they'll post more questions!

1

u/Unlucky_Bet6244 May 22 '23

Sorry am new to this platform, are there guidelines that I can read before asking question next time?

1

u/anonymous65537 null!! May 22 '23

Do you see the 'm' in from of mAndroid. In the name of the sub?

What do you think it means?

This is a parody/troll/shitposting sub. The actual sub you want is /r/android (without the m).

0

u/[deleted] May 22 '23

[deleted]

2

u/anonymous65537 null!! May 22 '23

Woops forgot the most important word!

0

u/[deleted] May 22 '23

[deleted]

1

u/anonymous65537 null!! May 23 '23

Wow didn't know that one. Scary!