I have a 176,000 word SQLite database and an app that searches it (via an IntentService
) and works great, never crashing. Even if thousands of "hits" are returned, the user can scroll through the list quickly and seamlessly. But I often-to-maybe-always get the Logcat warning message shown in the Title.
I've use a Cursor
to access the database data and a TextView
inside a ScrollView
, as shown:
<ScrollView
...>
<TextView
android:id= "@+id/txaMatches"
android:scrollbars= "vertical"
.../>
</ScrollView>
code:
// initialize, etc.
Cursor cursor = mdatabase.query(TABLE_NAME, mColumns, whereClause,
wildCardReplacements, null, null, WORD_COLUMN_NAME);
nRows = cursor.getCount();
while (n <= prefMaxMatches && i < nRows) {
cursor.moveToPosition(i);
// do stuff
}
But the warning makes me wonder if making a change in the code to get rid of it might improve responsiveness. Some searches take awhile (i.e., output not immediate, but given in a reasonable time period), depending on the Pattern
entered (e.g., *
must search all 176,000 words). Anyone could live with it, but we always want more speed.
What should I do? Just ignore the warning since it causes no apparent unacceptable action (e.g., crashing, slow execution)? Or what?
EDIT
Pztar suggests using LIMIT 50
in the query, but it's not entirely clear how to do so. Here's how--append LIMIT 50
to the "order by" column name (which, for me, is WORD_COLUMN_NAME
):
String __whereClause = "word like ?";
String[] __wildCardReplacements = {pattern};
cursor = mdatabase.query(TABLE_NAME, mColumns, __whereClause,
__wildCardReplacements, null, null,
WORD_COLUMN_NAME + " LIMIT 50");
--or, as better suggested by cricket_007,--
use the version of the call to query
that has one more parameter:
cursor = mdatabase.query(TABLE_NAME, mColumns, __whereClause,
__wildCardReplacements, null, null,
WORD_COLUMN_NAME, "50");