Questions tagged [android-livedata]
Android LiveData holds the value and allow it to observe changes and also respects lifecycle of the app components.
2,872
questions
0
votes
1
answer
35
views
Utils classes are belongs to which layer in MVVM architecture?
I'm currently working on an Android project following the MVVM architecture pattern. While organizing my code, now I'm confused about placement of utility classes. In which package i should place ...
0
votes
0
answers
23
views
Android DataBinding fails to update views after fragment resumes
I have one activity with only a FragmentContainerView, who's fragment is initiated right in the XML of the activity:
<?xml version="1.0" encoding="utf-8"?>
<androidx....
0
votes
2
answers
35
views
Changing LiveData WHERE clause
I have a Room Dao method like this:
@Query("SELECT * FROM stuff WHERE x == :y")
LiveData<List<Stuff>> getStuff(int y);
And in my ViewModel I have this variable:
LiveData<List&...
0
votes
1
answer
34
views
Is there a way to reset the value of a MutableLiveData?
I noticed there's a NOT_SET value in LiveData. Is there a way to reset a MutableLiveData to this? Basically, I have a use case where I want to reset the MutableLiveData back to like it was never set.
0
votes
0
answers
18
views
Does MutableLivedata mean getting live updates from server like sockets?
how does MutableLivedata work exactly?
UI components observe the MutableLiveData objects, and they are notified of data updates only when there is a change in the observed data. How does ...
0
votes
1
answer
19
views
Should the Viewmodel of a DetailFragment be shared amongst instances?
I wrote a master fragment that shows a list of stores, call it StoreFeedFragment. If you click on a store it calls newInstance of StoreDetailFragment to provide details of the clicked store. Both ...
0
votes
1
answer
69
views
Jetpack Compose can't observe MutableLiveData
View
viewModel.todoLists.observe(lifecycleOwner){
it?.let { label.value = it.toString() }
}
ViewModel
val todoLists : MutableLiveData <ListResponse> = MutableLiveData()
fun ...
-1
votes
0
answers
33
views
Why can't I get the data from my ViewModel to my View even though it's loaded in the ViewModel?
Viewmodel
fun login(username: String, password: String) {
loginIsLoading.value = true
jwt.value = "initial"
viewModelScope.launch {
try {
...
1
vote
1
answer
43
views
LiveData observer triggered again on fragment back navigation
I am building an Android app that displays a list of categories using a RecyclerView in a Fragment. When the user taps on a category, I navigate to the same Fragment with the child categories of the ...
0
votes
0
answers
25
views
Problem with keeping records in RecyclerView when rotating the screen
I am developing an Android application on my own, applying the knowledge learned in the courses "Android Basics in Kotlin", "Modern Android app architecture", "Advanced ...
0
votes
1
answer
51
views
MVVM Should I Move View Logic to ViewModel?
For MVVM, I understand that the general consensus is to make the view as "dumb" as possible. In the context of Android, would it be incorrect to do any type of display logic in the View(...
0
votes
0
answers
51
views
Observe live data returned from a function
If I return a request by liveData in a function and observe it in an activity to show the response, will my activity always observe liveData or only when the function is called?
viewModel:
fun ...
0
votes
1
answer
26
views
Event wrapper Android - How to clear the first observer?
I'm reading a lot about that, but I can't find a solution. I've never used before MutableLiveDate and I found out the event wrapper approch, but I'm finding some problem to use it.
The code below ...
0
votes
2
answers
80
views
How to add a new item to a MutableLiveData MutableList? (Android - Kotlin)
I have a variable:
private var a = MutableLiveData<MutableList<Int>>()
Variable that I want to assign a value to when the button is clicked.
For example for every click, add a new random ...
0
votes
1
answer
53
views
How to migrate this from LiveData to Kotlin Flow on Android?
I'm new to Kotlin Flow on Android.
Can you please tell me how I can migrate this LiveData code to Flow?
class MyViewModel @Inject constructor(private val myRepository: MyRepository) : ViewModel() {
...
1
vote
1
answer
27
views
Can't remove observer
I have a observer in Main activity, when its value changes navigate to other page, so I only wanna it to observe once. But inside removeObserver, there is always an error, "Unresolved reference: ...
2
votes
1
answer
77
views
Use lazycolumn jetpack compose lag more than use recycleview
I just learned jetpack compose and I switched from recycle to lazy column but when I do it it lags much more than recycle
after adding about 100 items to the application the app is lagging, is there ...
2
votes
1
answer
65
views
My live data is getting updated but doesn't trigger the observer in android kotlin
I have a livedata variable which I keep listening from my main activity for possible changes to do some operations in the UI thread, but unfortunately it isn't getting triggered. And please note the ...
0
votes
2
answers
73
views
Problem getting data from database in Android Kotlin Room
I'm new to mobile developpment. I am trying to get LiveData from the Room database in a Fragment, I get no errors but the Observer callback is null. My database contains data, i can access the login. ...
0
votes
1
answer
30
views
MutableLiveData, RecyclerView refresh on delete
I'm a totally newby using Kotlin and I'm trying to create my first app with a lot of test and error (and have worked till now).
My problem is that I have created a recyclerview that have rows from ...
1
vote
2
answers
38
views
How to use LiveData into ViewModel in Android
In my application I want to use Viewmodel with LiveData and for this I used this tutorial : ViewModel with LiveData
But I have one question, why used LiveData such as below :
private val _flavor = ...
0
votes
1
answer
122
views
androidx.lifecycle.LiveDataReactiveStreams class not found after version 2.6.0
I just started to play with LiveData.
I followed the official Android documentation to import the different artifacts. Everything was fine until I needed to convert an Observable to LiveData. But ...
0
votes
1
answer
66
views
Jetpack Lifecycle: Fragment's View Lifecycle never reaching CREATED state, never destroyed
Problem
I recently noticed one case when in an Android app, the following exception is triggered:
java.lang.IllegalArgumentException: Cannot add the same observer with different lifecycles
It happens ...
0
votes
1
answer
33
views
How to trigger MutableLiveData change in ui?
In my view model I'm using an observable with zip operator to combine two data sets where I then create a new object with data from each source. I post the value of the object to my ui. I need to be ...
0
votes
1
answer
24
views
Mock Injected private variable in Activity
class CustomActivity : BaseActivity() {
@Inject
lateinit var viewModelFactory: ViewModelProviderFactory
private val mViewModel: SplashViewModel by viewModels {
viewModelFactory
}
override fun ...
1
vote
1
answer
56
views
Is there a difference between using Live Data as a parameter and using return?
I create functions in ViewModel to avoid repetition when using Flow and LiveData. In an example, I created an extension function as follows. While talking to my friend, we started to think about the ...
0
votes
0
answers
16
views
viewmodel and LiveData in Android
Sorry I have to delete my post because I was not getting answers from the stackflow community. I felt it was not necessary to leave the post here then.
0
votes
1
answer
33
views
Flow<Set<CategoriesItemResponse>> does not seem to emit new transform value after reordering contents
I'm using preferences DataStore for persisting a simple Set of CategoriesItemResponse (I know this is not a good practice, but that is beside the point). I have a Flow<Set<CategoriesItemResponse&...
0
votes
0
answers
15
views
Execution point not reaching the composable call below the code for viewmodel livedata observer in parent composable (Jetpack Compose)
I have created composables as :
var namesList : List<Names> = emptyList()
@Composable
fun NameScreen(viewModel: NameViewModel = hiltViewModel()){
val lifeCycleOwner = LocalLifecycleOwner....
1
vote
1
answer
81
views
Why declare mutableLiveData class with val type?
Why not use mutableLiveData of the val type as a substitute for the var type?
Isn't it a violation to be able to set on the val type?
Like, for example:
Example of a val type
class ...
0
votes
0
answers
25
views
Using livedata in fragments causing loss of state with bottomNavigation and NavigationController
I have been trying to find the cause and the solution for the loss of states and recreating the fragments of bottom navigation when I use LiveData and MutableLiveData data inside a fragment in ...
0
votes
1
answer
35
views
Update Composable State Across activity boundaries
I'm building a android application, that has multiple activities that share a data model.
The data model is composed of two layers:
The first stores a list of objects to be used, and methods for ...
0
votes
0
answers
80
views
LiveData List order/sort changed not triggering the observer
I have a LiveData<List<ReportRow>> that gets updated when the user changes the date range or changes the sort order of the data that comes from a SQLite DB.
I have a observer to observe ...
0
votes
0
answers
14
views
Updated to DiffUtil but getting null response in DiffResult used volley for data as json
your textUpdated working recyclerview to diffUtil which gets data in the form of json fro google sheet after initializing the diffUtil in adaper created method which shows invoke virtual method ...
0
votes
1
answer
36
views
Why use Transformations.switchMap?
Is there any advantage in using Transformations.switchMap like this
MutableLiveData<Integer> userId = ...;
LiveData<User> user = Transformations.switchMap(userIdLiveData, id -> ...
0
votes
1
answer
35
views
MutableList is not updated
I try to update MutableList's value within LiveData by function "addToArray".
But I get null, when I try to observe liveData into a fragment. What's happening? Please, any Advice?! May be, I ...
0
votes
1
answer
16
views
LiveData doesn't update value
I try to put value to liveFata from viewModelScope, but when I check that value within fragment it's null. I think, there is problem with instance of viewModel, but I can't find solution. Please, any ...
0
votes
1
answer
46
views
Android. When displaying a fragment on the screen, live data does not display the data
I recently started learning Android and I have a problem. I use MVVM, Coroutines, Live Data, Dagger 2, Retrofit in the project. The problem is that the data is not displayed in the Fragment in the ...
1
vote
1
answer
67
views
Kotlin MutableLiveData not changing
I have a loginStatus value declared as MutableLiveData:
val loginStatus = MutableLiveData<Boolean>()
When the user logins, the value will be changed to true in the viewModel:
withContext(...
1
vote
0
answers
16
views
Unable to observe the Data posted From ViewModel to Activity During Test Case
I am writing the Unit Test Case using the Roboelectric , basically I want to test my activity class UI ,but data coming from viewmodel and it's observed in activity and then it's set to the UI also ...
0
votes
1
answer
55
views
LiveData not updating from insert in Room
I want to propagate repository response to the user as a toast so i put live data listener in my activity on post create method
mainViewModel.toast.observe(this) {
Log.d(TAG, "...
0
votes
1
answer
45
views
Add Filters to a Room Query after Runtime in Kotlin
I have a Room query that I'm running when my app starts.
@Query("SELECT * FROM myTable")
fun get(): LiveData<List<MyItem?>?>
After the query runs, my user will select several ...
0
votes
1
answer
36
views
Activity cannot be cast to Application
I have weather app , which display weather in your own location and also shows date.
To show UI I use Fragment, and FragmentContainer.
Literrally , I don't really understand how to bind rest api ...
0
votes
1
answer
98
views
Waiting for liveData observe and return result
I'm new in Kotlin Mvvm and I have some problems with using live data Observe,
how can we observe live data in a function and return results?
my viewModel
fun fetchDictionary(word: String): LiveData<...
0
votes
0
answers
46
views
Getting database data to display from LiveData<List<Items>> and view model to a ListView UI component
I have created an application that stores grade data database information in Android Studio. It uses LiveData to return a list of all of the grades stored in the database. A view model is used to ...
0
votes
0
answers
44
views
savedStateHandle not restore data from livedata
I have a custom dialog fragment with 1 button. I have 1 case when this button do nothing.
When user clicks button, I call this method to save data from dialog:
fun <T : Any> Fragment....
-1
votes
1
answer
118
views
LiveData return null on Jetpack Compose Android [duplicate]
DAO
@Query("SELECT COUNT(category) FROM todolist_table")
fun getAllTaskCount() : LiveData<Int>
Repo
suspend fun getAllTaskCount() : LiveData<Int> {
return todoDao....
0
votes
0
answers
9
views
Exception while trying to retrieve data (a specific row) from Room database in android studio into a simple list rather than LiveData [duplicate]
I am completely new to the concept of Room databases in android studio. So, in order to understand how it works, I am trying to create a simple database that stores only two columns- a student's ID/...
0
votes
1
answer
33
views
Android ViewModel deletes all my data when observing
I am developing an app with Android Studio, and I wish to use MutableLiveData alongside with RecyclerView. Problem is, when I add a new item to the MutableLiveData, it gets updated, then going back to ...
0
votes
1
answer
22
views
Null Pointer Exception if changing toolbar icon on observe? Facing problem with kotlin
Having a filter Fragment A with custom toolbar which is used commonly for many fragments and activity for filter list on click of filter icon of toolbar opening Fragment B to set filter option and and ...