Java Code Examples for android.arch.lifecycle.Observer#onChanged()

The following examples show how to use android.arch.lifecycle.Observer#onChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingleLiveEvent.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
@MainThread
public void observe(LifecycleOwner owner, final Observer<T> observer) {

    if (hasActiveObservers()) {
        Log.w(TAG, "Multiple observers registered but only one will be notified of changes.");
    }

    // Observe the internal MutableLiveData
    super.observe(owner, new Observer<T>() {
        @Override
        public void onChanged(@Nullable T t) {
            if (mPending.compareAndSet(true, false)) {
                observer.onChanged(t);
            }
        }
    });
}
 
Example 2
Source File: SingleLiveEvent.java    From Android-VMLib with Apache License 2.0 6 votes vote down vote up
@MainThread
@Override
public void observe(@NonNull LifecycleOwner owner, @NonNull final Observer<T> observer) {
    if (single) {
        if (hasActiveObservers()) {
            L.d("Multiple observers registered but only one will be notified of changes.");
        }
        // Observe the internal MutableLiveData
        super.observe(owner, new Observer<T>() {
            @Override
            public void onChanged(@Nullable T t) {
                if (mPending.compareAndSet(true, false)) {
                    observer.onChanged(t);
                }
            }
        });
    } else {
        super.observe(owner, observer);
    }
}
 
Example 3
Source File: SingleLiveEvent.java    From settlers-remake with MIT License 6 votes vote down vote up
@MainThread
public void observe(LifecycleOwner owner, final Observer<T> observer) {

	if (hasActiveObservers()) {
		Log.w(TAG, "Multiple observers registered but only one will be notified of changes.");
	}

	// Observe the internal MutableLiveData
	super.observe(owner, new Observer<T>() {
		@Override
		public void onChanged(@Nullable T t) {
			if (mPending.compareAndSet(true, false)) {
				observer.onChanged(t);
			}
		}
	});
}
 
Example 4
Source File: SingleLiveEvent.java    From Word-Search-Game with GNU General Public License v3.0 5 votes vote down vote up
@MainThread
@Override
public void observe(@NonNull LifecycleOwner owner, @NonNull Observer<T> observer) {
    super.observe(owner, t -> {
        if (mPending.compareAndSet(true, false)) {
            observer.onChanged(t);
        }
    });
}