java - OutOfMemory on string which is response XML -
conditions:
i have url, returns me xml, ~3mb of data. string, parse xml, , save it. complete process happens in async task.
two problems:
- my ui thread blocked until server data parsed.
- i outofmemory error on string in cases
// calling code
{ httpentity entity = response.getentity(); inputstream in = entity.getcontent(); value = convertstreamtostring(in).tostring(); return value; } // helper function public static string convertstreamtostring(java.io.inputstream is) { try { return new java.util.scanner(is).usedelimiter("\\a").next(); } catch (exception e) { return ""; } catch (outofmemoryerror ex) { commonlib.zlog("splash", "out of memory exception while download"); return ""; } }
try this, if minimum version of sdk 11 or greater,
add following application tag in manifest
android:largeheap="true"
some of people says not best way,but in application working suggesting you.
hope you.
Comments
Post a Comment