tried LiveData+Coroutine but the issue is when cl...
# android
b
tried LiveData+Coroutine but the issue is when click a button need to call the Api ,first time working fine, second time request is not sending. Transformation is required here?
n
Could you provide us with some more info?
b
val login: LiveData<LoginResult> =liveData(Dispatchers.IO){ emit(LoginResult.Progress(true)) try { val data = loginRepository.login(LoginRequest()) emit(LoginResult.Success(data)) }catch (e:Exception){ emit(LoginResult.Failure(e)) }
this is the request function in viewmodel
In onClick Observing this live data, is this correct way?
r
does it emmit an error the second time
b
Not getting any error
g
if you take a look at how it livedata {} actually works you can see it runs your code when it becomes active so if you observe it in onclick i assume you didn't remove the previous observer, i think if you would remove it before observing again that would result in your expected behaviour
r
You should just attach a observer in onViewCreated .. not in onclick . Than when you do onClick than you should trigger this liveData , preferably with another livedata
b
@gergo tried in that way but not working.