How to handle large response from webservices in android
<p>Hi friends 
I am getting the large  value from webservice .My repsonses are coming character  like xml entity character references   I am replacing the  Character using strigescapeutils calss. I am storing my response in string .I am getting out of memory error .I am parsig the response using sax parser.I parsed the value and  stored in arraylist of beans .In arraylist value add it in textview </p>

<p>I am getting this error while doing this operations out of memory error.I don't know how to do in stream.can anybody tell how to do ? can anybody give example? is it possible add large value in arraylist of bean and string?</p>

<p>this is my reading parsing value using string parser</p>

<pre><code> xr.parse(new InputSource(new StringReader(webservicevalue)));
</code></pre>

<p>I am gettin this error </p>

<pre><code>I/dalvikvm(  418):   at android.view.ViewGroup.addInArray(ViewGroup.java:~1918)
I/dalvikvm(  418):   at android.view.ViewGroup.addViewInner(ViewGroup.java:1879)

I/dalvikvm(  418):   at android.view.ViewGroup.addView(ViewGroup.java:1756)
I/dalvikvm(  418):   at android.widget.TableLayout.addView(TableLayout.java:418)

I/dalvikvm(  418):   at android.view.ViewGroup.addView(ViewGroup.java:1713)
I/dalvikvm(  418):   at android.widget.TableLayout.addView(TableLayout.java:400)

I/dalvikvm(  418):   at android.view.ViewGroup.addView(ViewGroup.java:1693)
I/dalvikvm(  418):   at android.widget.TableLayout.addView(TableLayout.java:391)

I/dalvikvm(  418):   at com.inquest.HomeSearchArticle$HomeSearchTask.onPostExecu
te(HomeSearchArticle.java:210)
I/dalvikvm(  418):   at com.inquest.HomeSearchArticle$HomeSearchTask.onPostExecu
te(HomeSearchArticle.java:1)
I/dalvikvm(  418):   at android.os.AsyncTask.finish(AsyncTask.java:417)
I/dalvikvm(  418):   at android.os.AsyncTask.access$300(AsyncTask.java:127)
I/dalvikvm(  418):   at android.os.AsyncTask$InternalHandler.handleMessage(Async
Task.java:429)
I/dalvikvm(  418):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm(  418):   at android.os.Looper.loop(Looper.java:123)
I/dalvikvm(  418):   at android.app.ActivityThread.main(ActivityThread.java:4363
)
I/dalvikvm(  418):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm(  418):   at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm(  418):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.r
un(ZygoteInit.java:860)
I/dalvikvm(  418):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
618)
I/dalvikvm(  418):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(  418):
I/System.out(  418): ######out of memory error is###java.lang.OutOfMemoryError
W/System.err(  418): java.lang.OutOfMemoryError
W/System.err(  418):    at android.view.ViewGroup.addInArray(ViewGroup.java:1918
)
W/System.err(  418):    at android.view.ViewGroup.addViewInner(ViewGroup.java:18
79)
W/System.err(  418):    at android.view.ViewGroup.addView(ViewGroup.java:1756)
W/System.err(  418):    at android.widget.TableLayout.addView(TableLayout.java:4
18)
W/System.err(  418):    at android.view.ViewGroup.addView(ViewGroup.java:1713)
W/System.err(  418):    at android.widget.TableLayout.addView(TableLayout.java:4
00)
W/System.err(  418):    at android.view.ViewGroup.addView(ViewGroup.java:1693)
W/System.err(  418):    at android.widget.TableLayout.addView(TableLayout.java:3
91)
W/System.err(  418):    at com.inquest.HomeSearchArticle$HomeSearchTask.onPostEx
ecute(HomeSearchArticle.java:210)
W/System.err(  418):    at com.inquest.HomeSearchArticle$HomeSearchTask.onPostEx
ecute(HomeSearchArticle.java:1)
W/System.err(  418):    at android.os.AsyncTask.finish(AsyncTask.java:417)
W/System.err(  418):    at android.os.AsyncTask.access$300(AsyncTask.java:127)
W/System.err(  418):    at android.os.AsyncTask$InternalHandler.handleMessage(As
yncTask.java:429)
W/System.err(  418):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(  418):    at android.os.Looper.loop(Looper.java:123)
W/System.err(  418):    at android.app.ActivityThread.main(ActivityThread.java:4
363)
W/System.err(  418):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(  418):    at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err(  418):    at com.android.internal.os.ZygoteInit$MethodAndArgsCalle
r.run(ZygoteInit.java:860)
W/System.err(  418):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.ja
va:618)
W/System.err(  418):    at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm-heap(  418): Clamp target GC heap from 17.250MB to 16.000MB
D/dalvikvm(  418): GC freed 8999 objects / 786288 bytes in 466ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.467MB to 16.000MB
D/dalvikvm(  418): GC freed 9064 objects / 514760 bytes in 485ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.583MB to 16.000MB
D/dalvikvm(  418): GC freed 5354 objects / 317512 bytes in 450ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.583MB to 16.000MB
D/dalvikvm(  418): GC freed 670 objects / 20232 bytes in 534ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.588MB to 16.000MB
D/dalvikvm(  418): GC freed 1238 objects / 46104 bytes in 445ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.590MB to 16.000MB
D/dalvikvm(  418): GC freed 242 objects / 9944 bytes in 429ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.620MB to 16.000MB
D/dalvikvm(  418): GC freed 595 objects / 52232 bytes in 426ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.619MB to 16.000MB
D/dalvikvm(  418): GC freed 298 objects / 9024 bytes in 398ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.666MB to 16.000MB
D/dalvikvm(  418): GC freed 914 objects / 79712 bytes in 439ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.711MB to 16.000MB
D/dalvikvm(  418): GC freed 1378 objects / 94048 bytes in 467ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.710MB to 16.000MB
D/dalvikvm(  418): GC freed 176 objects / 4432 bytes in 492ms
I/dalvikvm-heap(  418): Forcing collection of SoftReferences for 1028-byte alloc
ation
I/dalvikvm-heap(  418): Clamp target GC heap from 17.709MB to 16.000MB
D/dalvikvm(  418): GC freed 81 objects / 1296 bytes in 714ms
E/dalvikvm-heap(  418): Out of memory on a 1028-byte allocation.
I/dalvikvm(  418): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm(  418):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b268 self=0
xbd00
I/dalvikvm(  418):   | sysTid=418 nice=0 sched=0/0 cgrp=default handle=-13440013
84
I/dalvikvm(  418):   at android.text.StaticLayout.generate(StaticLayout.java:~13
8)
I/dalvikvm(  418):   at android.text.StaticLayout.&lt;init&gt;(StaticLayout.java:97)
I/dalvikvm(  418):   at android.text.StaticLayout.&lt;init&gt;(StaticLayout.java:54)
I/dalvikvm(  418):   at android.text.StaticLayout.&lt;init&gt;(StaticLayout.java:45)
I/dalvikvm(  418):   at android.widget.TextView.makeNewLayout(TextView.java:4914
)
I/dalvikvm(  418):   at android.widget.TextView.onMeasure(TextView.java:5176)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.widget.TableRow.getColumnsWidths(TableRow.java:3
08)
I/dalvikvm(  418):   at android.widget.TableLayout.findLargestCells(TableLayout.
java:497)
I/dalvikvm(  418):   at android.widget.TableLayout.measureVertical(TableLayout.j
ava:462)
I/dalvikvm(  418):   at android.widget.TableLayout.onMeasure(TableLayout.java:42
8)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.widget.ScrollView.measureChildWithMargins(Scroll
View.java:893)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.widget.ScrollView.onMeasure(ScrollView.java:276)

I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.widget.RelativeLayout.measureChildHorizontal(Rel
ativeLayout.java:569)
I/dalvikvm(  418):   at android.widget.RelativeLayout.onMeasure(RelativeLayout.j
ava:361)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.widget.RelativeLayout.measureChildHorizontal(Rel
ativeLayout.java:569)
I/dalvikvm(  418):   at android.widget.RelativeLayout.onMeasure(RelativeLayout.j
ava:361)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.LinearLayout.measureChildBeforeLayout(Lin
earLayout.java:888)
I/dalvikvm(  418):   at android.widget.LinearLayout.measureHorizontal(LinearLayo
ut.java:619)
I/dalvikvm(  418):   at android.widget.LinearLayout.onMeasure(LinearLayout.java:
280)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewRoot.performTraversals(ViewRoot.java:76
3)
I/dalvikvm(  418):   at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
I/dalvikvm(  418):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm(  418):   at android.os.Looper.loop(Looper.java:123)
I/dalvikvm(  418):   at android.app.ActivityThread.main(ActivityThread.java:4363
)
I/dalvikvm(  418):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm(  418):   at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm(  418):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.r
un(ZygoteInit.java:860)
I/dalvikvm(  418):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
618)
I/dalvikvm(  418):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(  418):
D/AndroidRuntime(  418): Shutting down VM
W/dalvikvm(  418): threadid=3: thread exiting with uncaught exception (group=0x4
001b188)
E/AndroidRuntime(  418): Uncaught handler: thread main exiting due to uncaught e
xception
I/dalvikvm-heap(  418): Clamp target GC heap from 17.723MB to 16.000MB
D/dalvikvm(  418): GC freed 309 objects / 11840 bytes in 425ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.723MB to 16.000MB
D/dalvikvm(  418): GC freed 39 objects / 3144 bytes in 402ms
I/dalvikvm-heap(  418): Forcing collection of SoftReferences for 1402-byte alloc
ation
I/dalvikvm-heap(  418): Clamp target GC heap from 17.723MB to 16.000MB
D/dalvikvm(  418): GC freed 0 objects / 0 bytes in 448ms
E/dalvikvm-heap(  418): Out of memory on a 1402-byte allocation.
I/dalvikvm(  418): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm(  418):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b268 self=0
xbd00
I/dalvikvm(  418):   | sysTid=418 nice=0 sched=0/0 cgrp=default handle=-13440013
84
I/dalvikvm(  418):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractSt
ringBuilder.java:~97)
I/dalvikvm(  418):   at java.lang.AbstractStringBuilder.append0(AbstractStringBu
ilder.java:131)
I/dalvikvm(  418):   at java.lang.StringBuffer.append(StringBuffer.java:273)
I/dalvikvm(  418):   at java.io.StringWriter.write(StringWriter.java:138)
I/dalvikvm(  418):   at java.io.PrintWriter.doWrite(PrintWriter.java:711)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:686)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:661)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:729)
I/dalvikvm(  418):   at java.io.PrintWriter.print(PrintWriter.java:492)
I/dalvikvm(  418):   at java.io.PrintWriter.println(PrintWriter.java:623)
I/dalvikvm(  418):   at java.lang.Throwable.printStackTrace(Throwable.java:316)
I/dalvikvm(  418):   at android.util.Log.getStackTraceString(Log.java:234)
I/dalvikvm(  418):   at com.android.internal.os.RuntimeInit.crash(RuntimeInit.ja
va:315)
I/dalvikvm(  418):   at com.android.internal.os.RuntimeInit$UncaughtHandler.unca
ughtException(RuntimeInit.java:76)
I/dalvikvm(  418):   at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java
:887)
I/dalvikvm(  418):   at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java
:884)
I/dalvikvm(  418):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(  418):
I/dalvikvm-heap(  418): Clamp target GC heap from 17.728MB to 16.000MB
D/dalvikvm(  418): GC freed 88 objects / 7896 bytes in 426ms
I/dalvikvm-heap(  418): Forcing collection of SoftReferences for 1126-byte alloc
ation
I/dalvikvm-heap(  418): Clamp target GC heap from 17.728MB to 16.000MB
D/dalvikvm(  418): GC freed 0 objects / 0 bytes in 429ms
E/dalvikvm-heap(  418): Out of memory on a 1126-byte allocation.
I/dalvikvm(  418): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm(  418):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b268 self=0
xbd00
I/dalvikvm(  418):   | sysTid=418 nice=0 sched=0/0 cgrp=default handle=-13440013
84
I/dalvikvm(  418):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractSt
ringBuilder.java:~97)
I/dalvikvm(  418):   at java.lang.AbstractStringBuilder.append0(AbstractStringBu
ilder.java:131)
I/dalvikvm(  418):   at java.lang.StringBuffer.append(StringBuffer.java:273)
I/dalvikvm(  418):   at java.io.StringWriter.write(StringWriter.java:138)
I/dalvikvm(  418):   at java.io.PrintWriter.doWrite(PrintWriter.java:711)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:686)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:661)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:729)
I/dalvikvm(  418):   at java.io.PrintWriter.print(PrintWriter.java:492)
I/dalvikvm(  418):   at java.io.PrintWriter.println(PrintWriter.java:623)
I/dalvikvm(  418):   at java.lang.Throwable.printStackTrace(Throwable.java:316)
I/dalvikvm(  418):   at android.util.Log.getStackTraceString(Log.java:234)
I/dalvikvm(  418):   at com.android.internal.os.RuntimeInit.crash(RuntimeInit.ja
va:323)
I/dalvikvm(  418):   at com.android.internal.os.RuntimeInit$UncaughtHandler.unca
ughtException(RuntimeInit.java:76)
I/dalvikvm(  418):   at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java
:887)
I/dalvikvm(  418):   at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java
:884)
I/dalvikvm(  418):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(  418):
I/Process (   58): Sending signal. PID: 418 SIG: 3
I/dalvikvm(  418): threadid=7: reacting to signal 3
I/dalvikvm(  418): Wrote stack trace to '/data/anr/traces.txt'
I/Process (  418): Sending signal. PID: 418 SIG: 9
I/ActivityManager(   58): Process com.inquest (pid 418) has died.
I/WindowManager(   58): WIN DEATH: Window{43ce0a18 com.inquest/com.inquest.Login
Activity1 paused=false}
I/WindowManager(   58): WIN DEATH: Window{43d6b028 com.inquest/com.inquest.HomeA
ctivityGroup paused=false}
I/WindowManager(   58): WIN DEATH: Window{43dab588 com.inquest/com.inquest.Hello
TabWidget paused=false}
I/ActivityManager(   58): Start proc com.inquest for activity com.inquest/.Login
Activity1: pid=428 uid=10026 gids={3003, 1015}
D/dalvikvm(   29): GC freed 312 objects / 12104 bytes in 337ms
D/dalvikvm(   29): GC freed 52 objects / 2296 bytes in 338ms
D/ddm-heap(  428): Got feature list request
D/dalvikvm(   29): GC freed 2 objects / 56 bytes in 292ms
I/UsageStats(   58): Unexpected resume of com.inquest while already resumed in c
om.inquest
W/InputManagerService(   58): Got RemoteException sending setActive(false) notif
ication to pid 418 uid 10026
I/ActivityManager(   58): Displayed activity com.inquest/.LoginActivity1: 4444 m
s (total 4444 ms)
</code></pre>
