logo
down
shadow

Fragment not receiving LiveData updates after remove + add


Fragment not receiving LiveData updates after remove + add

By : nayito
Date : November 28 2020, 08:01 AM
hop of those help? As per the Lifecycle.State.DESTROYED documentation:
code :


Share : facebook icon twitter icon
Using Realm and LiveData. Converting LiveData<RealmResults<CustomModelObject>> to LiveData<List<Custom

Using Realm and LiveData. Converting LiveData<RealmResults<CustomModelObject>> to LiveData<List<Custom


By : zawminoo
Date : March 29 2020, 07:55 AM
Any of those help In your case, replacing LiveData with LiveData> would be enough to solve your problem.
However, I'd advise trying out the RealmLiveResults class that is available in the official example:
code :
/**
 * This class represents a RealmResults wrapped inside a LiveData.
 *
 * Realm will always keep the RealmResults up-to-date whenever a change occurs on any thread,
 * and when that happens, the observer will be notified.
 *
 * The RealmResults will be observed until it is invalidated - meaning all local Realm instances on this thread are closed.
 *
 * @param <T> the type of the RealmModel
 */
public class LiveRealmResults<T extends RealmModel> extends LiveData<List<T>> {
    private final RealmResults<T> results;

    // The listener will notify the observers whenever a change occurs.
    // The results are modified in change. This could be expanded to also return the change set in a pair.
    private OrderedRealmCollectionChangeListener<RealmResults<T>> listener = new OrderedRealmCollectionChangeListener<RealmResults<T>>() {
        @Override
        public void onChange(@NonNull RealmResults<T> results, @Nullable OrderedCollectionChangeSet changeSet) {
            LiveRealmResults.this.setValue(results);
        }
    };

    @MainThread
    public LiveRealmResults(@NonNull RealmResults<T> results) {
        //noinspection ConstantConditions
        if (results == null) {
            throw new IllegalArgumentException("Results cannot be null!");
        }
        if (!results.isValid()) {
            throw new IllegalArgumentException("The provided RealmResults is no longer valid, the Realm instance it belongs to is closed. It can no longer be observed for changes.");
        }
        this.results = results;
        if (results.isLoaded()) {
            // we should not notify observers when results aren't ready yet (async query).
            // however, synchronous query should be set explicitly.
            setValue(results);
        }
    }

    // We should start observing and stop observing, depending on whether we have observers.

    /**
     * Starts observing the RealmResults, if it is still valid.
     */
    @Override
    protected void onActive() {
        super.onActive();
        if (results.isValid()) { // invalidated results can no longer be observed.
            results.addChangeListener(listener);
        }
    }

    /**
     * Stops observing the RealmResults.
     */
    @Override
    protected void onInactive() {
        super.onInactive();
        if (results.isValid()) {
            results.removeChangeListener(listener);
        }
    }
}
Android LiveData: Not receiving all notifications

Android LiveData: Not receiving all notifications


By : user1381329
Date : March 29 2020, 07:55 AM
it fixes the issue The explanation lies in the implementation for postValue and mPostValueRunnable:
code :
protected void postValue(T value) {
    boolean postTask;
    synchronized (mDataLock) {
        //this is true on the first run or right after the observer receives an update
        postTask = mPendingData == NOT_SET;
        mPendingData = value;
    }
    // this statement will be true if the observer hasn't received an update even though it's sent to the main looper
    if (!postTask) { 
        return;
    }
    ArchTaskExecutor.getInstance().postToMainThread(mPostValueRunnable);
}

private final Runnable mPostValueRunnable = new Runnable() {
    @Override
    public void run() {
        Object newValue;
        synchronized (mDataLock) {
            newValue = mPendingData;
            mPendingData = NOT_SET;//once this value is reset a new mPostValueRunnable can be sent
        }
        // here the observer will receive the update
        setValue((T) newValue);
    }
};  
Not receiving the data change at LiveData

Not receiving the data change at LiveData


By : ToKENiZ0R
Date : March 29 2020, 07:55 AM
should help you out You are post value to Repository MutableLiveData but observing MyViewModel LiveData. Merge them or use only one
Try it like this
code :
public LiveData<List<MyObj>> fetchList(){
   return repository.getList();
}
mViewModel.fetchList().observe(this, new Observer<List<MyObj>>(){...}
Update value of LiveData everytime one of other LiveData updates its value

Update value of LiveData everytime one of other LiveData updates its value


By : A Dey
Date : March 29 2020, 07:55 AM
it should still fix some issue You can make it more reactive-style using the extension function feature of Kotlin.
Assume that you have firstLiveaData and secondLiveData with the same type of T. Now you want to filter them first and then listen to all of their changes.
code :
fun <T> LiveData<T>.filter(predicate : (T) -> Boolean): LiveData<T> {
    val mutableLiveData = MediatorLiveData<T>()
    mutableLiveData.addSource(this) {
        if(predicate(it))
            mutableLiveData.value = it
    }
    return mutableLiveData
}

fun <T> MediatorLiveData<T>.addSources(vararg listOfLiveData: LiveData<T>, callback: (T) -> Unit) {
    listOfLiveData.forEach {
        addSource(it, callback)
    }
}
fun <T> merge(vararg liveDataList: LiveData<T>): LiveData<T> {
    val mergedLiveData = MediatorLiveData<T>()
    liveDataList.forEach { liveData ->

        liveData.value?.let {
            mergedLiveData.value = it
        }

        mergedLiveData.addSource(liveData) { source ->
            mergedLiveData.value = source
        }
    }
    return mergedLiveData
}
fun doSomething() {
    val firstLiveData = MutableLiveData<List<SomeType>>()
    val secondLiveData = MutableLiveData<List<SomeType>>()

    merge(firstLiveData, secondLiveData).filter { someFilterFunction() }.observe(...)
}
Android Architecture Component(LiveData): How to clear all value from LiveData once it updates a textview

Android Architecture Component(LiveData): How to clear all value from LiveData once it updates a textview


By : Caulnian
Date : March 29 2020, 07:55 AM
To fix this issue You would not do this.
One of the main reasons to use LiveData is to have other components be able to observe the contents of the LiveData.
Related Posts Related Posts :
  • What could be causing my WhatsApp Stickers Pack not to work?
  • How Can I Reorder/Sort The Collections List in Directus?
  • Is this language generic/mighty enough to be used for a generic game AI?
  • graphite, use regular expressions to select the target, or an alternative
  • subtract functions with type real in ml
  • how to filter '(' in navision 2013
  • sending sms from a mobile browser
  • NuGet behind firewall
  • Gstreamer hangs while generating timelapse from JPEGs on Raspberry pi
  • How to retrieve total view count of large number of pages combined from the GA API
  • Websites rich with exercices or explanation for SML?
  • Is there a TempData equivalent in ServiceStack?
  • scipy-0.12.0 failing to install on mountain lion using python setup.py install
  • Looking for simplest option to render Razor cshtml pages in a console application without any web server
  • Evaluating variables at a specific time in Modelica
  • When I run the Application, only "web" engine is running in GlassFish. "webservices" is not started
  • How To Set MIME Type Of Google Drive File
  • Remove Missing Values in Weka
  • Reloading a UICollectionView using reloadData method returns immediately before reloading data
  • carrot2 - can I cluster documents from a folder?
  • StreamSocket has no Close Implementation in C#
  • Rails, Foundation 4, Respond.js not working properly in IE8
  • How can i create imagesurface from cairo xlib's Graphics Context using cairo and x11 Api's?
  • CKEditor "overflow: scroll" on parent causes toolbar to freeze at initial position
  • Differences between components and controls in ENYO
  • Photoshop making isometric?
  • Does Intel IPP 8.0 support in-place operations?
  • What is Object dictionary in CANOpen?
  • Example of orbBasic Indexed User Variables
  • convert to ABSOLUTE in logback
  • How to conditionally download file using p:fileDownload
  • Error on pod install
  • Set HTTP GET Parameters in Finagle
  • different attack that uses sql injection
  • How can I change my xampp username not as 'root'
  • AMQP Content header payload structure
  • Apache POI formula evaluation not working for Excel IF
  • How can I trace RESTEasy's dispatch?
  • Map Freezes on iOS 7 with Google Maps SDK 1.4
  • Comparing lists, is the subset list within the first list
  • Non-ascii character highlight in Sublime Text 2
  • Installing Magit in Aquamacs
  • Receiving error - System.Net.Mail.SmtpException: 4.3.2 try again later
  • Coreaudio render callback in monotouch
  • The command 'yarn --v' also initiates 'yarn install' and installs packages automatically. Why is this happening?
  • save multiple matches in a list (grep or awk)
  • Can a number register be used in a groff request?
  • Mapping FAQ with RASA for large dataset (2000+)
  • FitText.js makes text bigger rather than smaller
  • ARM - Implementing stack with load/store multiple register values
  • How to check if a ChromeCast Session is already in progress
  • ngForm inside a Carousel Slide in UI Bootstrap not working
  • Clearing attributes in Tritium
  • "vagrant up" failing: Vagrant VM failed to remain in the running state
  • ftsearch returning empty docs
  • What are the advantages of setting "hive.exec.parallel" to false in Hive ?
  • Creating a root certificate in FiddlerCore
  • How to access app.config in a blueprint?
  • DB2 RECORDSET table name converted to uppercase
  • Resizing the superview according to the subviews
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org