LiveData which publicly exposes setValue(T) and postValue(T) method.
Questions tagged [mutablelivedata]
320 questions
5
votes
0 answers
Not able to import InstantTaskExecutorRule in my 'jUnit' test case even after adding 'core-testing' dependency - Android testing
I am writing test cases for my LoginViewModel. Where I want to perform setValue() operation on my MutableLiveData.
To avoid Method getMainLooper in android.os.Looper not mocked Exception I am trying to add the following Rule in my ViewModel file…

Kavita Patil
- 1,784
- 1
- 17
- 30
5
votes
5 answers
How to stop LiveData event being triggered more than Once
I am using MutableLiveData within my application for event based communication. I have single activity two fragments architecture.
With the help of ViewModel, I'm consuming the LiveData events in Fragment-1. But, when I replace this Fragment-1 with…

Ningan
- 151
- 1
- 8
5
votes
3 answers
MVVM - MutableLiveData of Custom Model not been updating into ViewModel with databinding and always is null
Summary:
When I try to send to the repository a custom Model, the MutableLiveData is null. I think it is because of the observer of the MutableLiveData.
Please, read to the end.
ViewModel
class LoginViewModel @Inject constructor(
private val…

Faustino Gagneten
- 2,564
- 2
- 28
- 54
4
votes
1 answer
LiveData transformations map functionality
Recently i've been learning transformations methods on LiveData
I know that we can use map or switchMap method to transform livedata.
Let's say we have Player data class similar below
data class Player(val name: String, val score: Int = 0)
And we…

nasibeyyubov
- 1,735
- 3
- 11
- 28
4
votes
2 answers
Android Unit Test: How to mock an object which contains MutableLiveData but only exposes LiveData?
I have a repository class that uses a MutableLiveData object, exposed as just LiveData, to return results of async web queries to a ViewModel. The ViewModel then uses Transformation to map the results to another MutableLiveData which is observed by…

ThePMO
- 413
- 4
- 13
4
votes
1 answer
Using liveData{} coroutine builder on Dispatchers.IO thread
My code
fun weatherByCity(cityName: String): LiveData> = liveData(Dispatchers.IO) {
val response = appRepository.weatherByCity(cityName)
emit(response)
}
fun weatherByZipCode(zipCode: String): LiveData>…

Sharad
- 589
- 5
- 19
4
votes
1 answer
Replace getLoaderManager().initLoader with MutableLivedata
getLoaderManager has been deprecated with android 28. ViewModel, Repository and Room replace the loader functionality
I have found 2…

Theo
- 2,012
- 1
- 16
- 29
4
votes
1 answer
Android: Setting LiveData as MutableLiveData
Firstly i might not actually be understanding what mutable live data is correctly.
i get data from room using live data and then show it to the UI, it is a question with answers, so at the end of the question i would like to update the database with…

Dave
- 313
- 1
- 3
- 16
4
votes
3 answers
Why does LiveData better than MutableLiveData?
In many samples i see that:
class DataViewModel{
val data:LivaData
get() = _data
private val _data = MutableLiveData()
}
But more simply looks like this:
class DataViewModel{
val data =…

Serg Burlaka
- 2,351
- 24
- 35
4
votes
1 answer
Using an ArrayAdapter with LiveData.
I'm familiar with MVVM in WPF, but am in the process of porting an existing Android app to make use of a ViewModel class and LiveData for the first time.
The app "as/was" has a custom ArrayAdapter that is used to correctly display the items…

JoeHz
- 2,136
- 1
- 18
- 29
4
votes
1 answer
How to observe changes in database in order to update LiveData
I am migrating an app from a LoaderManager with Callbacks to an implementation using ViewModel and LiveData. I would like to keep using the existing SQLiteDatabase.
The main implementation works OK. The Activity instantiates the ViewModel and…

Paul Naveda
- 724
- 8
- 16
4
votes
1 answer
android : mutablelivedata change is not updating the UI
I am using MutableLiveData to store a choice user has made. The value is set from another activity. SO onResume i am calling
myMutableLivedata.value = newvale
But this does not update the UI unless i call a invalidateall().
Is this expected…

png
- 4,368
- 7
- 69
- 118
4
votes
1 answer
Observing LiveData from Room causes PagedListAdapter to refresh, ViewModel refreshes data also on orientation changes
I'm building an app that uses ArticleBoundaryCallback to init a call to an API, and store the response in Room. I'm also listening to that table using LiveData, and displaying the items in a PagedListAdapter.
The problem is that every time new data…

jorjSB
- 610
- 4
- 12
3
votes
1 answer
LiveData value not updating UI in Jetpack Compose until I navigate out
I am calling an increaseCount(id: String) method from a composable to increase the value of a parameter in a LiveData List of objects. The value gets updated quite alright but the UI only shows the update once I navigate out. PS: I am using a…

MrBE
- 103
- 2
- 10
3
votes
1 answer
Mutable live-data give multiple response give old response from api and after give new response
**Mutable live-data give multiple response old response from api and after give new response **
mutable live-data give multiple response
here is my code
Repository
suspend fun forgotPassword(email:String,sig: String,salt:…

androi useru
- 81
- 10