title: Set up AsyncTask for loading data from SQLite database?
body: <p>The onCreate() method below works fine in my Activity to create a CardView from SQLite data:</p>
  
  <pre><code>helper = new SQLiteDB(this);  
  listItems = new ArrayList&lt;&gt;();
  listItems = helper.getAllListItems();
  </code></pre>
  
  <p>When I try to set up an AsyncTask() method to replace the last line above and load the database data in the List, the CardView shows on the UI but does not populate with the SQLite data.  What am I missing here?</p>
  
  <p>CardViewDetailsActivity</p>
  
  <pre><code>public class CardViewDetilsActivity extends AppCompatActivity {
  
      List&lt;ListItem&gt; listItems;
      private SQLiteDB helper;
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_dets);   
  
          final CardView cardView = (CardView) findViewById(R.id.dets);
  
          // Get the position of the clicked on R. list CardView from
          // the MainActivity's intent bundle.
          Bundle extras = getIntent().getExtras();
          if (extras != null) {
              // get the CardView item using the int position from the
              // MainActivity's onItemClick() and the putExtra in the intent.
              position = extras.getInt("position",0); 
          } 
  
          helper = new SQLiteDB(this);
          listItems = new ArrayList&lt;&gt;();
          listItems = helper.getAllListItems(); 
          // I tried to replace the last line above with:
          // "getDataFromSQLiteDB();" to launch the AsyncTask();
  
          ...
          cardType1 = (TextView) findViewById(R.id.cardType1);
          ...  
          cardType1.setText(listItems.get(position).getType()); 
      } // End of onCreate();
  
      private void getDataFromSQLiteDB() {
  
          new AsyncTask&lt;Void, Void, Void&gt;() {
              @Override
              protected Void doInBackground(Void... params) {
                  listItems.clear();
                  listItems.addAll(helper.getAllListItems());
                  // I also replaced the above two lines with 
                  // helper.getAllListItems();
  
                  return null;
              }
              @Override
              protected void onPostExecute(Void aVoid) {
                  super.onPostExecute(aVoid);
              }
          }.execute();
      }
  }   
  </code></pre>
  
  <p>SQLiteDB.java</p>
  
  <pre><code>public class SQLiteDB extends SQLiteOpenHelper {
  
      // Get data from the database that the CardViewDetails Activity can use
      public List&lt;ListItem&gt; getAllListItems() {
      List&lt;ListItem&gt; modelList = new ArrayList&lt;&gt;();
  
      SQLiteDatabase db = getReadableDatabase();
      ...
          return modeList;    
      }
  }
  </code></pre>