Changes

Jump to: navigation, search

An Android Room Database and Repository Tutorial

167 bytes removed, 18:37, 3 July 2018
no edit summary
The repository class will be responsible for interacting with the Room database on behalf of the ViewModel and will need to provide methods that use the DAO to insert, delete and query product records. With the exception of the getAllProducts() DAO method (which returns a LiveData object) these database operations will need to be performed on separate threads from the main thread using the AsyncTask class.
In addition, the AsyncTask to perform a product search will need to return the results to the repository object. This topic was covered in the chapter entitled TBD and begins with the addition of an interface class to the project. Add a new interface class named AsyncResult and modify it so that it reads as follows:
<pre>
== Adding the RecyclerView Adapter ==
As outlined in details the chapter entitled TBD, a A RecyclerView instance requires an adapter class to provide the data to be displayed. Add this class now by right clicking on the app -> java -> com.ebookfrenzy.roomdemo -> ui.main entry in the Project tool window and selecting the New -> Java Class... menu option. In the Create New Class Dialog, name the class ProductListAdapter. With the resulting ProductListAdapter.java class loaded into the editor, implement the class as follows:
<pre>

Navigation menu