https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
o

oday

02/16/2019, 12:09 AM
when starting a screen for example, inside onCreate and you’re hooking up things to do this call, is this how it would go?
Copy code
leaseCarsVM.getLeaseCarsResult().observe(this, getLeaseCarsObserver)
        leaseCarsVM.getLeaseCars(true)

        swiperefreshLayout.setOnRefreshListener {
            leaseCarsVM.getLeaseCarsResult().observe(this, getLeaseCarsObserver)
            leaseCarsVM.getLeaseCars()
        }
try moving it to say the beginning of the screen, all of them together hooked up to the various other observers, and then make the VM calls later, they don’t come back successfully, has to be before the call..
d

dewildte

02/16/2019, 5:32 PM
It looks to me like a
LifecycleOwner
and LiveData
Observer
is being used to observe changes to a list of cars. The only code you should be putting in refresh listener is the request to get more cars.
The observer would handle passing the new list to the adapter.
So only 1 observer is needed while the view exists.
In a fragment I would put the initialization and observation code in
onActivityCreated()
o

oday

02/17/2019, 12:39 PM
yes but if you try this, the requests don’t go out and come back properly
because yes of course what you’re saying makes sense, it’s like a listener
go treat it like one, set all the listeners initially and then make the requests later, no go
they simply dont come back
2 Views