title: Android SQLite get all data from cursor fast
body: <p>I am dealing with a performance problem in one of my apps. Maybe one of you guys can help me out?!</p>
  
  <p>I have a database with somewhat around 10k entries.
  I query for elements using the default <em>query</em> method from the <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html" rel="nofollow">SQLiteDatabase</a>-class.
  The query itself is fast enough.</p>
  
  <p>Once the query is complete I have to display the results on a Google Map.
  For that I generate a result array from the cursor which holds the marker information.</p>
  
  <p>The method I use looks somewhat like this:</p>
  
  <pre><code>    final ArrayList&lt; MarkerElement &gt; result = new ArrayList&lt; MarkerElement &gt;();
      cursor.moveToFirst();
      while ( !cursor.isAfterLast() ) {
          result.add( new MarkerElement(
                  cursor.getString( COL_TITLE ),
                  cursor.getString( COL_SNIPPET ),
                  new LatLng(
                          cursor.getDouble( COL_LAT ),
                          cursor.getDouble( COL_LNG ) ),
                  cursor.getString( COL_OTHER_USEFUL_DATA ) );
          cursor.moveToNext();
      }
      cursor.close();
  </code></pre>
  
  <p>Where <em>MarkerElement</em> is simply a class that holds the required values for a Marker on a Google Map.</p>
  
  <p>The problem now is, that looping through all cursor elements takes by far to long.
  Also I cannot think of a smart way to lazy load the results like in a ListView because I need to show all results simultaneously.</p>
  
  <p>Is there anything I can do to speed up this process significantly?</p>
  
  <p>Any help is greatly appreciated!</p>
  
  <p>Best regards</p>