androidx.lifecycle.DefaultLifecycleObserver Java Examples
The following examples show how to use
androidx.lifecycle.DefaultLifecycleObserver.
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: Selection.java From SAI with GNU General Public License v3.0 | 5 votes |
public void observe(LifecycleOwner lifecycleOwner, Observer<Key> observer) { if (lifecycleOwner.getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) return; addObserver(observer); lifecycleOwner.getLifecycle().addObserver(new DefaultLifecycleObserver() { @Override public void onDestroy(@NonNull LifecycleOwner owner) { removeObserver(observer); } }); }
Example #2
Source File: SelectableAdapter.java From SAI with GNU General Public License v3.0 | 5 votes |
public SelectableAdapter(Selection<Key> selection, LifecycleOwner lifecycleOwner) { mSelection = selection; if (lifecycleOwner.getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) return; lifecycleOwner.getLifecycle().addObserver(new DefaultLifecycleObserver() { @Override public void onDestroy(@NonNull LifecycleOwner owner) { unregisterObservers(); } }); }
Example #3
Source File: ConversationListFragment.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void initializeViewModel() { viewModel = ViewModelProviders.of(this, new ConversationListViewModel.Factory()).get(ConversationListViewModel.class); viewModel.getSearchResult().observe(this, this::onSearchResultChanged); viewModel.getMegaphone().observe(this, this::onMegaphoneChanged); ProcessLifecycleOwner.get().getLifecycle().addObserver(new DefaultLifecycleObserver() { @Override public void onStart(@NonNull LifecycleOwner owner) { viewModel.onVisible(); } }); }