Android.database.cursorwindowallocationexception: Cursor Window Allocation Of 2048 Kb Failed Even After Closing Cursor
There are many questions on SO about CursorWindowAllocatoinException: SQLite Android Database Cursor window allocation of 2048 kb failed Could not allocate CursorWindow Out of Mem
Solution 1:
I was querying the database from a service. When I did it from an activity, the problem never occurred again.
Alongside querying, I was reading from the serial port within the same service. Maybe that caused the problem. However, when I used an activity instead of the service, the problem never happened again.
Solution 2:
i had the same problem in my application while loading more than 500 songs from android media store.
closing the cursor will not solve your problem.
you should use AsyncTask.. inside doInBackground method write the code for retrieving values from cursor.
public class CursorLoader extends AsyncTask {
@Overrideprotected Void doInBackground(Void... params) {
Stringquery="select serial from tbl1 union select serial from tbl2 union select serial from tbl3";
SQLiteDatabasedb=null;
Cursorcur=null;
try {
SettingsDatabaseHelperdal=newSettingsDatabaseHelper(
c);
db = dal.getReadableDatabase();
cur = db.rawQuery(query, null);
intnumRows= cur.getCount();
if (numRows > 0) {
cur.moveToFirst();
intserialIdx= cur.getColumnIndexOrThrow("serial");
for (booleanhasItem= cur.moveToFirst(); hasItem; hasItem = cur
.moveToNext()) {
Stringserial= cur.getString(serialIdx);
if (Validator.getInstance().isValidSerial(serial))
serials.add(serial);
}
}
} finally {
if (cur != null)
cur.close();
if (db != null)
db.close();
}
returnnull;
}
@OverrideprotectedvoidonPreExecute() {
}
@OverrideprotectedvoidonPostExecute(Void result) {
}
Solution 3:
I had the same problem, while i am calling the DATA BASE, in the service class using forever loop.
My code was like:
service ()
{
void run()
{
while(conditionisTrue)
{
db.getRecord(); //I remove this code from here and put it in the start of service c
}
}
}
Post a Comment for "Android.database.cursorwindowallocationexception: Cursor Window Allocation Of 2048 Kb Failed Even After Closing Cursor"