LiveData which publicly exposes setValue(T) and postValue(T) method.
Questions tagged [mutablelivedata]
320 questions
0
votes
2 answers
Avoid LiveData triggered twice
I have such issue:
Two fragments: A and B, which inject viewModel, but for some reason I have result of LiveData in both of my fragments.
How can I avoid triggering live data pushing me old value? How to reset liveData somehow or ignore old values?…

yozhik
- 4,644
- 14
- 65
- 98
0
votes
1 answer
How to use mutable live data of type sealed class with data binding
I am trying to handle visibility of a ProgressBar using mutable LiveData of type sealed class with data binding but getting below error.
cannot find symbol variable sealed class
Below is my code
ViewModel
class RevampSplashViewModel:…

Shahbaz Hashmi
- 2,631
- 2
- 26
- 49
0
votes
1 answer
Use observe for a variable that updated inside another observe in Kotlin
I am trying first handle the response from API by using observe. Later after observing the handled variable I want to save it to database.
The variable tokenFromApi is updated inside tokenResponseFromApi's observer. Is it possible to observe…

isifzade
- 480
- 1
- 5
- 16
0
votes
0 answers
Mutable Live data is triggering only once even after the value is set
Mutable Live data is triggering only once. I have a singleton class in which an instance of mutable live data is created once and I am calling a retrofit to get some response inside the singleton method the response is set to Mutable Live data and…

Uday Kumar
- 1
- 1
0
votes
1 answer
LiveData, Room persistant Ui is not updated
I am building an android app using Room for the data persistence and LiveData.
I have multiple fragments and viewModel.
When i start the app and land on the MainActivityView, I am also placing a call to retrieve the userinformation and save it in…

Seb
- 2,929
- 4
- 30
- 73
0
votes
1 answer
ViewModel not updating the view on postValue
I used the lifecycle callback onCreate to fetch data like below
mWeOutViewModel.getPlaceListLiveData()
.observe(this, weOutItemViewModels -> {
AppLogger.i(getCustomTag() + "adding items " + weOutItemViewModels.size());
…

TheLetch
- 375
- 1
- 4
- 15
0
votes
1 answer
How to prepend list in kotlin
Hey I want to prepend item in list in kotlin. I am trying to add item but unfortunately, I am getting error, can someone guide me how to do that.
val prepareMutableLiveData: MutableLiveData
- > = MutableLiveData(
…

Kotlin Learner
- 3,995
- 6
- 47
- 127
0
votes
1 answer
How to make a view disappear in time
I have a fragment that starts after a list item is clicked to display details about the item. Depending on the item I want a view inside the details fragment to either show or not show. I'm trying to use DataBinding and LiveData to set the value…

brandNoob
- 47
- 6
0
votes
3 answers
LiveData not updated in ViewModel
In my ViewModel class I have a method that fetches data from the internet and sets them on LiveData via setValue() (I've used the approach from these docs):
public class PageViewModel extends ViewModel {
private MutableLiveData
- >…

prosp
- 97
- 2
- 11
0
votes
1 answer
I can not use livedata on databinding
I'm trying to reach my value as livedata in xml but I getting this error " java.lang.RuntimeException: Failed to call observer method" and "Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()'…

Seyfi
- 1
- 2
0
votes
2 answers
LiveData not firing when Inside Network Change Callbacks in Android View Model - Kotlin
Trying to listen to a Connection call back using Live Data.
The Callbacks "onAvailable" and "onLost" are fired, but the "postValue" inside the ViewModel is not fired. It is first only once when the AppViewModel is initialized and the init is called…

Kikki
- 496
- 1
- 10
- 17
0
votes
1 answer
MutableLiveData is not posting the correct value - Android
I'm building an app around a Meals API. First a list of categories will be shown. On selecting a category, meals of the particular category will be displayed. Users can add any meal to favorites. User can see the list of favorites by clicking on the…

Neeraja Gandla
- 97
- 1
- 6
- 17
0
votes
1 answer
LiveData.value returns Null But Livedata Direct Observe it getting result
View Image Here
When I want to set live-data to mutable live data I call live data.getvalue() but it returns null
private const val TAG = "MainViewModel"
@HiltViewModel
class MainViewModel @Inject constructor(private val repository: VaultRepository)…

Vamsi Reddy
- 41
- 1
- 5
0
votes
1 answer
LiveData change not observed when Item data changes in the List
I am trying to observe Item data changes in a List using LiveData. But for some reason it is not working as expected.
ViewModel
@HiltViewModel
class TestScreenViewModel @Inject constructor(private val repository: TestRepository) :
ViewModel()…

user1418628
- 1
- 1
0
votes
0 answers
SingleLiveEvent with conditional trigger
I am using nested fragments so fragment1 opens fragment2 and they share a viewmodel.
This viewmodel calls a repository to get data and using a LiveData it posts the result and then fragment2 displays the data.
My problem was the second time…

user2327866
- 3
- 2