Questions tagged [android-livedata]

Android LiveData holds the value and allow it to observe changes and also respects lifecycle of the app components.

LiveData is part of new Android Architecture Components

LiveData used as holder to put values and allow it to be observed. It also respects lifecycle of the app components viz. onCreate(), onDestroy() etc. It is part of Android Architecture Lifecycle library which comes with Lifecycles, LiveData, and ViewModel.

LiveData is usually used with ViewModel to bind it with view and observe the changes accordingly. It is active when one or more active Observers are subscribed and is in-active when they are no active observers.(Active Observers means observers [Activity, Fragment] which are in STARTED or RESUMED state. As it is Lifecycle aware we can share it among multiple activities and fragments etc.

Diagram explains its place in Android Architecture Components. Android Architecture Component Flow

As shown in diagram, It gets data from repository and can be observed in Activity or Fragment via ViewModel

You can find more about it below

2899 questions
1
vote
1 answer

Passing value to LiveData in Android

I'm new in development and I'm aware that stack isn't for 'full code requests'. But I'm stuck and can't find the solution. I'm using Room database which has two columns - firstName and lastName. I'm loading the database with passed firstName…
1
vote
1 answer

MPAndroidChart: multiple LineDataSet from LiveData in a LineChart

Looking at other examples, I see that the chart needs all the data sets at once and you cannot add them iteratively once they are ready. Am I wrong? ArrayList dataSets = new…
adriennoir
  • 1,329
  • 1
  • 15
  • 29
1
vote
0 answers

Android Transformations.switchMap implementation

I've followed https://github.com/googlecodelabs/android-build-an-app-architecture-components. I want to be able to fetch weather data by city name. I've created the required method in the DAO class. I've changed my code in the Repository class to: …
user1080528
  • 75
  • 1
  • 6
1
vote
1 answer

Concurrency issue with LiveData on Android

I am trying to manipulate the data pulled from an API using retrofit and LiveData. Below is my code viewModel.getTransactions("withdrawals").observe(this, Observer { if (it.getError() == null) { dataAdapter =…
1
vote
1 answer

Android Pagination library in ArrayAdapter

How can I use the pagination library in the ArrayAdapter (I dont want to use ListView or RecyclerView)? categories is a list of string to be shown. I have a huge list of categories. I want it to be paginated. How to achieve this? List
Anup Ammanavar
  • 432
  • 1
  • 3
  • 16
1
vote
1 answer

Android LiveData and provider/manager pattern

I'm working on an app where a data source is defined in a Provider/Manager. This class (let's call it InfoProvider) is pretty much just a black box - it has some properties, and calls that when executed, result in change of these properties (similar…
fonix232
  • 2,132
  • 6
  • 39
  • 69
1
vote
0 answers

ViewModel + Livedata + Databinding + Transformations... How to?

I'm trying to transform a response from server to my databinding object... I didn't understand too much how i make that with the Transformations of livedata... I think i'm i need to change few things, but i didnt find what i need to…
Felipe A.
  • 929
  • 3
  • 12
  • 28
1
vote
2 answers

Why is onChanged not called when value changed in LiveData List?

Context Using MutableLiveData> to hold a values. When the first value (using first value as example for brevity) in the List is incremented, TextView should update in onChanged to display the first value in the List. Goals Increment…
surajs02
  • 451
  • 7
  • 18
1
vote
1 answer

Android Architecture sample unit testing live data

@Test fun sendResultToUI() { val foo = MutableLiveData>() val bar = MutableLiveData>() `when`(userRepository.loadUser("foo")).thenReturn(foo) `when`(userRepository.loadUser("bar")).thenReturn(bar) …
1
vote
0 answers

How to add new item to Room (ORM) With LiveData and display it as first item in RecyclerView

I am Using Room Persistent Data of Android, to store data coming from the server - locally. In addition, I am using MVVM pattern, recommended by Android official docs, thus my recyclerView gets displayed inside a LiveData Observer something like…
1
vote
1 answer

How to convert normal data(returned from room) to LiveData on ViewModel layer

I am using the clean architecture with MVVM pattern so the room part goes into the data layer and I'm returning observables from there to domain layer and using them in presentation layer by wrapping them in a LiveData. Now, the problem is that…
1
vote
2 answers

Combining different sources in RxJava MVVM (FCM, Networking, ROOM)

I have previously used MediatorLiveData to combine results from FCM, Room and Networking in my Repository. It worked well. However, now I want more complexity and some additional bonuses from RxJava. This is why I have decided to use RxJava this…
1
vote
1 answer

Show relevant ListView elements corresponding to another listview in navigation view where both lists are dynamic

I have two custom dynamic list views, one in a navigation view and one in the main layout like so
masked_man
  • 11
  • 2
1
vote
1 answer

android paging library - which DataSource I should use

What I Want: I want to implement Android Paging Library with network call only. What I Understood: So, DataSource has three classes that I can extend. PageKeyedDataSource: If your web service has pageNumber in url then you can use…
1
vote
1 answer

is this the correct way of LiveData usage?

I am currently applying Room + ViewModel + LiveData to my project. In my app, there is "obviously" observe data that is needed, but not all. The code below is example code for category data. In my situation, category data does not change and always…
1 2 3
99
100