I’ve the following code :
(basically it creates various JSONObjects (beneficiario) and put them all inside another JSONObject (proposta). I don’t show it here but I’ve Cursors (ppt, c) created before
if (ppt.getString(45).equals("0")) {
int i = 0;
c.moveToFirst();
JSONObject ben = new JSONObject();
try {
while (c.isAfterLast() == false)
{
i++;
ben.put("b_nome" + i, c.getString(1));
ben.put("b_telefone" + i, c.getString(2));
ben.put("b_nif" + i, c.getString(3));
ben.put("b_bi" + i, c.getString(4));
ben.put("b_codigopostal" + i, c.getString(5));
ben.put("b_localidade" + i, c.getString(6));
ben.put("b_morada" + i, c.getString(7));
}
} catch (JSONException e) {
e.printStackTrace();
}
proposta.put("beneficiario" + i, ben);
}
And it gives a outofmemory error, I guess that’s because I’m running it on main thread.
Can you give me an help/some code to use a thread or asynctask to do it?
use
c.moveToNext();in yourWhileloop. YourCursoris running Infinite.