title: How to check inside UI whether data exist in a table? By using Loader or just query()?
body: <p>How to check inside UI whether data exist in a table? 
  By using Loader or just query()?</p>
  
  <p>Which way is better? </p>
  
  <p>1) Using Loader.</p>
  
  <pre><code>    @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          getActivity().getSupportLoaderManager().restartLoader(POPULATE_CATEGORY_LIST_VIEW_LOADER, null, this);
  
      } 
  
  
          @Override
      public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor data) {
  
          switch (loader.getId()) {
              case POPULATE_CATEGORY_LIST_VIEW_LOADER:
  
                  if (!data.moveToFirst()) {
  
                      // load data from server and store data to db
  
                  }
  
                  break;
              default:
                  break;
          }
      }
  </code></pre>
  
  <p>2) Using getContentResolver().query() from UI</p>
  
  <pre><code>        Cursor locationCursor = getContext().getContentResolver().query(
                  MenuContract.CategoryEntry.CONTENT_URI,
                  new String[]{MenuContract.CategoryEntry._ID},
                  null,
                  null,
                  null);
  
          if(!locationCursor.moveToFirst()) {
              // load data from server and store data to db
          }
  </code></pre>
  
  <p>I just need to check whether data exist id db. Then if there are no data in a table, load data from server and put to an Adapter, otherwise just put data to the Adapter.
  How to do it correctly using Loaders?</p>
  
  <p>I understood that in both ways we need to wait until data base gives an answer. So maybe just querying a Cursor is enough for this task or it is bad practice to query data base from UI thread directly?</p>