Real Time Data from Sqlite database through Room outside Activity/Fragment following MVVM Model

橙三吉。 提交于 2019-12-11 22:15:08

问题


I am following the MVVM Model. I would like to have Real-time data from SQLite database through Room (Results shall available as soon as data changes in Database). With LiveData, we can get results in Activity/Fragment. Callback also won't good on this type of requirement since data should be pushed from the database. Is there any way I can get in any class outside of activity/fragment?.

Thanx in advance for your help.

EDIT

Putting sample code for better understanding..Is there a way to observe Room database Table so that we always have latest data from table?

  Filter filter =  mCustomerFilterDao.fetchcustomerSettings(settings);
  // Want to add observe for filter table so that we have latest customer 
  //settings. This is my Query.
  List<Book> booklist = new ArrayList<>();

 for(Book book:bookrecords)
 {
   if(book.status == filter.status)
     {booklist.add(book);}
  }

来源:https://stackoverflow.com/questions/53830522/real-time-data-from-sqlite-database-through-room-outside-activity-fragment-follo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!