https://kotlinlang.org logo
#android
Title
# android
a

Aveepsit Chowdhury

10/26/2019, 12:09 PM
Hello everyone, I'm super new to Android and trying to build a App with the mvvm architecture. From the many tutorials on YouTube I could figure out how to use Observerable and LiveData for data from ViewModel to View but how do I send the events of the View to the ViewModel like button clicks?
you can read up on this
p

Pablichjenkov

10/26/2019, 2:51 PM
Some people refer to messages from ViewModel to View
events
and messages from View to ViewModels
actions
. You can call any ViewModel action dispatcher method directly from the ViewModel reference you have in your View. Assuming you dispatch them from the Main Thread you wouldn't need a queue inside the ViewModel. If you plan to dispatch actions to the ViewModel from more than one thread, then you should have an action queue inside your ViewModel that process them one by one. This will avoid multi threading issues. For that you can research for Redux Store in Redux arch. But for simply handling View actions like clicks, direct dispatch is fine.
3 Views