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

How to update a recylerview elements inside a fragment whose data or property is changed (Room Database) from other activity

This is my code so far. Fragment to which recylerview is attached. public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mRestaurantLandingPage =…
1
vote
0 answers

Syncing data between room sqlite and server

I'm stuck in between development of my "notes" app. I am using Andoid liveData + ViewModel + Room. My concern is whenever I add/update/delete any note from my Local sqlite DB, how to sync this change with the DB in my server. Any help regarding the…
1
vote
2 answers

How to obtain simple List from Android LiveData>?

I'm new to Android and learning the same by developing simple app which consists of single Customer table which I'm accessing using android Room database. The Customer entity class is @Entity(tableName = "Customers") public class CustomerEntity…
1
vote
1 answer

Observable/LiveData of ActionBar visibility?

I am trying to see if it is possible to create an observable, that would notify when action bar visibility changes. Something in a way of LiveData actionBarVisibility; So that other UI can be updated when actionBar is shown/hidden? I found…
Paul
  • 1,879
  • 1
  • 23
  • 44
1
vote
1 answer

Better way to change listId/query in data source paging

I can't find a better way to change listId of my VideosDataSource methods like load initial. I'm using view pager so it load 2 fragment at a time that's why i can't use getter/setter to set listId of my data source. here my data source class: class…
1
vote
0 answers

Aggregating fields using Android Live Data

I have been running into an issue and currently don't see a better solution. My requirements: I have an mutable list of mutable models and I need to sum a big decimal inside the mutable model. Here is the solution that I came up with but I'm trying…
Andres S
  • 471
  • 1
  • 5
  • 19
1
vote
1 answer

How to show ProgressDialog when fetching data from ViewModel

I want to show ProgressDialog while fetching data from ViewModel and it works fine when I fetch data for the first time, but when I want to refresh the data from API the ProgressDialog starts and does not stops I create MutableLiveData()…
1
vote
0 answers

Nested LivaData Implementation

I'm learning how android architecture components work. For that, I'm trying to build a weather application. I want to get the location from the device and after that fetch weather at that location. For this, I'm using Two LiveData Objects, One for…
1
vote
0 answers

Re-initialise livedata object

Is it possible to have a live data property just reinitialize with the value it was set with? for example in the ViewModel we have... val apiKey = MutableLiveData().apply { value = context.apiKey } say context gets the API Key from…
aidanmack
  • 518
  • 1
  • 5
  • 16
1
vote
0 answers

Is it possible to use MutableLiveData with an array of object?

There's a fragment on the app I'm working on that the user needs to fill up to 6 EditText. Each pair of EditText represents the type and description of the user's address (as in "Apartment" as the Type and "1201" as the description). According to…
1
vote
1 answer

How to binding MutableLiveData using Custom objects?

MutableLiveData value is not being filled when I'm trying to use data binding to do it. When I use MutableLiveData in primary objects like Strings, it works fine. But if I try to use with a custom object the MutableLiveData#value is getting…
1
vote
1 answer

Send a parameter to Kotlin retrofit call

I am a beginner in Kotlin. I need to send a variable parameter from my Activity to a Retrofit call. This is my call in on Create of Detail Activity override fun onCreate(savedInstanceState: Bundle?) { //... val id =…
Andy
  • 751
  • 1
  • 12
  • 25
1
vote
1 answer

Live data observer not triggered after room db query

I have a LiveData object which i'm observing within a fragment within an activity. The activity listens to broadcasts from the system via 2 broadcast receivers. The data is queried from room according to the current date. So the receivers detect if…
1
vote
0 answers

Move socket.io implementation from android activity to Android-Architectural-Component repository, Is it allowed or is it a good idea?

I'm updating my code to MVVM implementation with the Android-Architectural-Component and I'm thinking if it is a good idea to also move my socket from the activity to the repository.
TABZ
  • 71
  • 9
1
vote
1 answer

LiveData not being set, observer never being called

I'm trying to save an "Episode" in my MainViewModel and allow other Fragments to have access to it via that ViewModel. In MainActivity I'm observing changes in the ViewModel, which is never being triggered. Weirdly, it works fine for my MainFeed RSS…
MrBovineJoni
  • 296
  • 1
  • 3
  • 15