https://kotlinlang.org logo
Title
r

rsktash

01/20/2022, 11:36 AM
Hi when device orientation changes connection between UI and Model being closed. Did I miss something I’ve not tested orientation changes before
a

Arkadii Ivanov

01/20/2022, 11:49 AM
Hello. I think I will need more details. How do you write the UI? How do you bind the UI and the data?
r

rsktash

01/20/2022, 11:50 AM
I’m using Jetpack Compose ui is bound via Decompose
a

Arkadii Ivanov

01/20/2022, 11:51 AM
Alright. So what is the issue? Is something not working after the orientation change?
r

rsktash

01/20/2022, 11:52 AM
Yes after orientation change ui is not updated and intents are not delivered to Store too
No forget about what I said before the connection is not lost What is lost is subscription to event updates from another service I’ve subscribed to another service in
Store.executeAction
via
scope.launch { flow.collectLatest}
I’m sorry )
When I comment this block It works properly. Now I’m starting the service in
Store.executeAction
a

Arkadii Ivanov

01/20/2022, 12:33 PM
Sorry, it is still not clear to me. I think I will need more code to help with the issue. How is the store created? Does the Action fire after orientation change?
r

rsktash

01/20/2022, 12:39 PM
No Action is fired on Store creation. At the end I moved this code to here
a

Arkadii Ivanov

01/20/2022, 12:45 PM
Is your Store retained?
r

rsktash

01/20/2022, 12:47 PM
Store is not destroyed on configuration changes
a

Arkadii Ivanov

01/20/2022, 12:51 PM
So perhaps the issue is because when mediaPlayer#deAttach is called, the subscription Flow inside the Store completes. Your workaround is reasonable. But you should be also able to call attach/deAttach in the place where you actually subscribe. Something like:
scope.launch {
    mediaPlayer.attach()
    mediaPlayer.data.collectLatest(...)
    mediaPlayer.deAttach()
}