Thread
#compose
    l

    loloof64

    1 year ago
    Hi 👋. Let's say I've have a complex object I want to persist even if the screen is rotated as state: should I use
    ViewModel
    or
    remeberSaveable
    ? Which is best practice ?
    a

    allan.conda

    1 year ago
    Are you just talking about config change? You can override all config change so your activity does not get recreated, so the state is retained
    l

    loloof64

    1 year ago
    In fact, I would like the user to be able to rotate the phone, and have a part of the @Composable updated, but not its state.
    a

    allan.conda

    1 year ago
    Yeah, Compose will react automatically when config changes without losing state, if you do above
    l

    loloof64

    1 year ago
    Thank you : I'll try it right now 😃
    I've just found on Android Documentation (https://developer.android.com/guide/topics/resources/runtime-changes#HandlingTheChange) that using
    configChanges
    should be used as a last resort. And that
    ViewModels
    can be adapted for large data. So I think I'll use ViewModels, as my issue was due to the fact that I relied on the
    Bundle
    providen by
    rememberSaveable
    with too much data 😃
    Colton Idle

    Colton Idle

    1 year ago
    Sounds like your complex object should just be persisted to a db, or to a file (remember... you have to worry about process death too) and then you save the state of the id of that complex object. Also, what you read about configChanges is the "old" guidance. I'm sure the official guidance will be updated at some point to include saying that you should override configChanges in a pure compose app.