Yes. You can have several outstanding queries from the same stream and access each of the cursors independently.
I added the following code to the test activity and it works as expected:
SQLiteDatabase connection = getApplicationContext().openOrCreateDatabase("foo.db", MODE_PRIVATE, null); try { connection.execSQL("drop table if exists person"); connection.execSQL("create table person (id integer, name string)"); ContentValues cv = new ContentValues(); cv.put("id", 1); cv.put("name", "leo"); connection.insert("person", null, cv); cv = new ContentValues(); cv.put("id", 2); cv.put("name", "yui"); connection.insert("person", null, cv); Cursor rs = connection.query("person", new String[] {"id", "name" }, null, null, null, null, null); while(rs.moveToNext()) { System.out.println("name = " + rs.getString(1)); System.out.println("id = " + rs.getString(0)); Cursor rs2 = connection.query("person", new String[] {"id", "name" }, null, null, null, null, null); while (rs2.moveToNext()) { System.out.println("name = " + rs2.getString(1)); System.out.println("id = " + rs2.getString(0)); } } } catch (Exception e) { System.out.println("Exception " + e); }
source share