I have 10 mb database and this code:
cursor = mDatabase.query(CitySQLiteHelper.TABLE_CITIES, ALL_COLUMNS, null, null, null, null, "name DESC", "20");
if (cursor.getCount() > 0) {
//
}
Execution freezes for about 10 seconds at the if statement. I tried getCount and moveToFirst – it freezes in both cases. Query and all the calls to the cursor (getString() etc) after the first call work fine. Why?
Update: Schema
sqlite> .schema cities
CREATE TABLE cities (region text, name text, latitude float, longitude float);
sqlite> select count(*) from cities;
130070
As suggested in a comment, I created unique index and this helped.