tried LiveData+Coroutine but the issue is when cl...
# android
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?
Could you provide us with some more info?
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?
does it emmit an error the second time
Not getting any error
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
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
@gergo tried in that way but not working.