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
0 answers

Android - LiveData is not unsubscribed when fragment is refreshed

So I have a weird scenario. I implemented an app which has a single Activity and two fragments. Both fragments have a filter option where they can select a category. Based on the category, the current fragment will refresh & fetch data with the new…
1
vote
1 answer

When should we extend LiveData class for MVVM architecture in android?

I have a bit of knowledge on LiveData and ViewModel, recently I tried to make an application using firebase real-time DB, but my usual approach of using just LiveData isn't working!. I am getting observed when data is changing but it is not bringing…
1
vote
1 answer

I do not receive changes to onChange when inserting data into the database

I'm trying to write applications with mvvm architecture. But I do not receive changes in onChange when I insert data into a database. The logic that I want to achieve: Go to the cache, take the data. Then we go to the server and receive data. If…
1
vote
1 answer

Using LiveData without LifecycleObserver

I'm writing an app which is (attempting) to adhere to the MVVM design pattern. I'd like to observe changes to the model layer from other parts of that layer. For example Let's say I'm exposing a list of objects from my database using…
FutureShocked
  • 779
  • 1
  • 10
  • 26
1
vote
2 answers

Change observed row in database when day changes and onCreate wasn't called

I am using Room database with LiveData. In Main activity I am showing data for current day. But when new day comes and onCreate wasn't called, views shows data for previous day. How can I properly refresh my data/views in…
OMIsie11
  • 459
  • 5
  • 19
1
vote
1 answer

Android LiveData> cast to LiveData>

I have generic problem, I have LiveData>, object User implement IEntity. How to cast LiveData> to LiveData>? package cz.roomlivedata.entity; import android.arch.persistence.room.Entity; import…
motorcb
  • 1,043
  • 3
  • 10
  • 19
1
vote
1 answer

Manifest merger failed after adding : annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"

Doing a tutorial about LiveData & ViewModel. In build.gradle I added: // ViewModel and LiveData implementation "androidx.lifecycle:lifecycle-extensions:2.0.0" Project synced without a problem. Then I added (1): annotationProcessor…
Werner
  • 314
  • 2
  • 11
1
vote
0 answers

How to update all live data the same time?

I want to update my live data(s) in my ViewModel when the app detects the user's filters changed on a drawer layout close listener. I have created an update all live data method in my ViewModel, but it doesn't seem to work. Here's my…
user10018802
1
vote
0 answers

Observer onChanged() does not send the latest value set

I am using LiveData and Room Database in a BroadcastReceiver. The main idea is to perform a single query on the database (insert, remove, get) and forward the updated value to the caller. Thanks to an Observer listening to the LiveData object, I am…
1
vote
1 answer

Android lifecycle observer

I've been learning about and using Android's new Jetpack feature WorkManager. The app basically sends images to the server in the background. It works well and the images are uploaded. The problem is when I attempt to observe the work status so…
1
vote
1 answer

Are there any reasons to ever scope LiveData to a fragment's lifecycle, rather than to the fragment's view's lifecycle?

If we scope LiveData to the lifecycle of a fragment by passing this to the observe method, the fragment doesn't get immediate updates if it is only detached from the activity, but not removed, because only the view is destroyed, not the fragment…
1
vote
1 answer

MutableLiveData observes while there is no change in data

I have experienced a weird behavior of MutableLiveData objects as they are sometimes observed continuously even without change in the data in it. As of my knowledge it should be observed only when it comes to active state from inactive state or the…
Vikash Bijarniya
  • 404
  • 4
  • 10
1
vote
1 answer

Handle no network in rxjava with retrofit

I am developing an application which doing network request using retrofit2 and rxjava2. I am doing it using MVVM approach which is in my RestInterface the result of the request returned in Flowable and in my repository I convert the Flowable into…
mangkool
  • 316
  • 2
  • 18
1
vote
1 answer

MediatorLiveData observer error for multiple calls

I work on a project that downloads some files if the login is successful and then opens Main Activity. If not so, it neither logins nor downloads files and prompts the user to login successfully to download the required files. After a failure, if a…
nuhkoca
  • 1,777
  • 4
  • 20
  • 44
1
vote
0 answers

How to get a LiveData list using Retrofit GET to populate a recyclerView

How to get a LiveData list using Retrofit GET to populate a recyclerView. My code is not showing the data on screen. Is onChange() called if I'm not changing an existing list, but starting with new data first time? MainActivity where I call the…
1 2 3
99
100