Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
remember
Currently, the pizza state is defined as a global variable. This is not ideal, since global variables in general can become tricky to manage and maintain. It would be better if the state were owned by the composable itself. Because composables are nothing more than functions, the only place to encapsulate state is inside the function itself.
This presents an issue: Because Compose will call your entire composable function from the ground up every time it recomposes your UI, any local variables you declare inside a composable function will be lost between compositions. If you tried to store state inside a composable, it would reset each time the composable is invoked – which is not an ideal mechanism for storing UI state. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access