I have following view model and observer in A Fragment(in onViewCreated
) which populates the recyelerview using adapter
commonOwnDBViewModel =
new ViewModelProvider(requireActivity()).get(CommonOwnDBViewModel.class);
Observer<List<FolderEntity>> notesObserver =
FolderEntityList -> {
folderNameAdapter.setListManager(FolderEntityList);
recyclerView.getAdapter().notifyDataSetChanged();
Toast.makeText(mActivity, "" + FolderEntityList.size(), Toast.LENGTH_SHORT).show();
};
commonOwnDBViewModel.getAllFolderEntityList
().observe(requireActivity(), notesObserver);
it gives me a list and works fine in the fragment now I want to use the same list in A service using Viewmodel and Observer how can we do that how do we manage Lifecycle in service.