title: How to to fetch data from SQLite db in a separate thread and use it in the main thread callback?
body: <p>I have a method in my <code>Fragment</code> that fetches values from a local database and puts this data in <code>RecyclerView</code>. The data fetching lasts long that retards UI, so I decide to put it in a separate thread. I want the separate thread to return a method call from my main thread.</p>
  <p>What are the best practices to do this?</p>
  <h1> Edit </h1>
  <p>I want to elaborate on my question, because the feedback I receive is not solving my problem. I will keep my original question untouched and edit the code.</p>
  <p>I want to call in my <code>Fragment</code> a method that would fetch from an <code>SQLite</code> database some data in a separate thread and, subsequently, call a callback in the main thread to make use of the fetched data to update the UI. The data will be used in <code>ReciclerView</code>. The code equivalent, as I imagine it, should look like this:</p>
  <pre><code>
  private Context context;
  private List&lt;T&gt; mData;
  
  @Override
  public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
      super.onViewCreated(view, savedInstanceState);
      context = getActivity();
  
      //-----------------Thread starts here.-------------------------
      List&lt;T&gt; threadData = getData();
  
      private List&lt;T&gt; getData(){
          List&lt;T&gt; returnList;
          ...Go in SQLite database (Context required) to populate returnList...
          return returnList;
      }
      //-------Thread ends here and calls threadOnFinish() callback in the  main thread--------
  }
  
  @Overwrite
  private void threadOnFinish(List&lt;T&gt; threadData,...){
      useData(threadData);
  }
  
  private void useData(List&lt;T&gt; newData){
      mData = newData;
      ...Use data and update UI...
  }
  </code></pre>
  <p>Please, help</p>