# compose

Nemanja Mladenović

08/28/2020, 7:17 PM
Beginner's question: how to interact with outside world from compose, lets say I have on click on a button and lets say that I want to start a service with that. Or the other way around, I get a message from service in a an activity holding composable, do I need to pass it to viewmodel and trigger recomposition via live data for example or do I have some other options?

Zach Klippenstein (he/him) [MOD]

08/28/2020, 7:25 PM
Depends on your architecture, but compose event handlers for things like button click are just functions. You can use them to invoke methods on your view model and then have your view model do side effects, or bubble it up your architecture further.
👍 1
As for flowing data back down, also depends on your architecture. Ideally in an app that's using unidirectional data flow, the ultimate source of truth for your data would eventually emit a new value when it is updated, which would then flow down your observables/flows/LiveDatas and eventually update your UI (compose or otherwise).
👍 2

Alejandro Rios

08/28/2020, 7:47 PM
@Nemanja Mladenović in case you missed, here's a related video

👍 2

Nemanja Mladenović

08/28/2020, 7:48 PM
I have seen it, but still wanted to check what is required to interact with outside world even if answer was kind of obvious
👍🏼 1