I have to execute a query and store the result in a list, the function that I use is this follow :
List<SpoolInDB> getSpoolInRecords(String label, boolean getLastInserted) {
List<SpoolInDB> spoolInList = new ArrayList<>();
try {
if (mdb == null)
mdb = mdbHelper.getWritableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE_SPOOLIN);
Cursor c = qb.query(mdb, null, " label='" + label + "'", null, null, null, " dateins " + (getLastInserted ? "desc" : "asc"));
if (c != null) {
c.moveToFirst();
if (c.getCount() > 0) {
int ndxid = c.getColumnIndex("id");
int ndxserverID = c.getColumnIndex("serverID");
int ndxlabel = c.getColumnIndex("label");
int ndxvalue = c.getColumnIndex("value");
int ndxpriority = c.getColumnIndex("priority");
int ndxdateins = c.getColumnIndex("dateins");
do {
SpoolInDB spoolIn = new SpoolInDB();
spoolIn.setId(c.getString(ndxid));
spoolIn.setServerID(c.getString(ndxserverID));
spoolIn.setLabel(c.getString(ndxlabel));
spoolIn.setValue(c.getString(ndxvalue));
spoolIn.setPriority(c.getString(ndxpriority));
spoolIn.setDateins(c.getString(ndxdateins));
spoolInList.add(spoolIn);
} while (c.moveToNext());
}
c.close();
}
} catch (Exception e) {
wil.WriteFile("4)DbGest - Exception: " + e.toString());
}
return spoolInList;
}
In a normal context this function work perfectly, but in some case this function produce an exception:
Window is full: requested allocation 3209815 bytes, free space 2096647 bytes, window size 2097152 bytes
This problem occour because in the "values" field I could store json datas that in some case could be bigger than 2mb, I can't forecast when the data is bigger than 2mb, I need a solution that work always.
How I can solve my problem ?