title: Android Room implementation with background threading handling queries
body: <p>I am recently trying to learn Android and I am very new to backend knowledge e.g. threading and stuff. I got Room figured out and try to integrate it with front end component. So, I am not worried how front end adapting the data I want it to present. I have the problem trying to design and implement the integration in a clean way using thread and trying to implement threading since I am new to it. </p>
  
  <p>Here is my code.</p>
  
  <p>Database.class</p>
  
  <pre><code>@Database(entities = {Groups.class, Member.class}, version = 1, exportSchema 
  = false)
  public abstract class DatabaseConfig extends RoomDatabase {
      private static final String DATABASE_NAME = "db";
      private static DatabaseConfig INSTANCE;
      public abstract GroupDao groupDao();
      public abstract MemberDao memberDao();
  
      public static DatabaseConfig getDatabase(final Context context) {
          if (INSTANCE == null) {
              synchronized (DatabaseConfig.class) {
                  if (INSTANCE == null) {
                      INSTANCE = 
                          Room.databaseBuilder(context.getApplicationContext(),
                              DatabaseConfig.class, DATABASE_NAME)
                              .addCallback(DatabaseCallBack)
                              .build();
                  }
              }
          }
          return INSTANCE;
      }
  
      private static RoomDatabase.Callback DatabaseCallBack =
          new RoomDatabase.Callback(){
  
              @Override
              public void onOpen (@NonNull SupportSQLiteDatabase db){
                  super.onOpen(db);
              }
          };
  }
  </code></pre>
  
  <p>GroupRepo.class</p>
  
  <pre><code>public class GroupRepo {
      private final GroupDao groupDao;
      //ExecutorService es = Executors.newSingleThreadExecutor();
  
      public GroupRepo (Context context){
          DatabaseConfig db = DatabaseConfig.getDatabase(context);
          groupDao = db.groupDao();
      }
  
      public List&lt;Groups&gt; getAllGroups(){
          /*
            So my idea is to have some sort of threading implement from here
            and use executor.run() to run my query and capture data
           */
      }
  }
  </code></pre>
  
  <p>Groups.class</p>
  
  <pre><code>@Dao
  public interface GroupDao {
      @Query("SELECT * from groups")
      List&lt;Groups&gt; getAllGroups();
  
      @Query("Select * from groups where groups.id = :groupsId")
      GroupAllMembers getAllMember(int groupsId);
  
      @Insert
      void insert(Groups... groups);
  
      @Delete
      void delete(Groups groups);
  }
  </code></pre>
  
  <p>I am not going to post my Entity class since my intention is not about that. I am fairly new to background threads. Please help and ideally provide some example to help me understand.</p>