SQL way too slow in Android... how do I speed it up?
I'm writing a keyboard app for android and I'm string key values in a SQL DB.
Here's an example row for one key. In the whole DB I have roughly 160 such rows.
(BTNID,TEXTADJUST,BUTTONSCALE,BUTTONSCALECNT,SPACINGLR,SPACINGTB,BTNOPA,BTNTEXT,BTNTEXTONCLICK,BTNTEXTONSHIFTCLICK,BTNTEXTCOLOR,BTNHUE,BTNSAT,LAYOUTSTDALTNUM,ATROW,BTNHUEHIT) VALUES('1','0','1','1','2','5','255','Q','qQ','Qq','0xFFFFFFFF','0','0','STD','1','0')
I'm reading this values by
TBL_NAME = pref开发者_C百科erences.getString("TBL", "EnglishZLayout");
SqlHelper sqlHelper = new SqlHelper(this, "TK.db", null, 1);
SQLiteDatabase DB = sqlHelper.getReadableDatabase();
String TBL_NAME_BTN = TBL_NAME.replace("ZLayout", "ZButtons");
Cursor c = DB.rawQuery("SELECT * FROM "+TBL_NAME_BTN, null);
c.moveToFirst();
while (c.isAfterLast() == false) {
...
and strangely it takes about 20-30 seconds to load. Any ideas how to speed it up?
I can't store key values within the app, since the user has to be able to change them.
Thanks!
You're not recreating the DB helper every time you execute the query, are you? Do this once on app startup.
To turn my comment into an "answer" for anyone else who might find this post:
- Try the loop without the actual button drawing code... you'll likely see that the SQL is not the problem
精彩评论