Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:04:05+00:00 2026-05-25T20:04:05+00:00

Following is simple method that connects to web service and receives the XML response

  • 0

Following is simple method that connects to web service and receives the XML response from server which is about 2.3MB and I’m getting OutOfMemoryError (I’ve referred this) but not being able to find my way, stuck badly

public synchronized String getUpdates(boolean news) throws Exception {
        String response = null; 
        HttpPost httppost;
        DefaultHttpClient httpclient;
        ResponseHandler <String> res=new BasicResponseHandler();  
        List<NameValuePair> nameValuePairs;
        httppost = new HttpPost(context.getString(R.string.SYNCURL));  
        HttpParams params = new BasicHttpParams();  
        HttpProtocolParams.setContentCharset(params, "UTF-8");

        String lastupdate = null;
        SharedPreferences preferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        lastupdate = preferences.getString(LAST_UPDATE, DatabaseHelper.updateDate);
        if(news) lastupdate = preferences.getString(LAST_UPDATE_NEWS, lastupdate);

        httpclient = new DefaultHttpClient(params);
        nameValuePairs = new ArrayList<NameValuePair>(2);  
        nameValuePairs.add(new BasicNameValuePair("reqDTTM", lastupdate));
        if(news)nameValuePairs.add(new BasicNameValuePair("doAction", "news"));
        if(!preferences.getString(LAST_UPDATE, "").equalsIgnoreCase(DatabaseHelper.updateDate)) {
            String timezon = UDFHelper.getTimeZon(context);
            nameValuePairs.add(new BasicNameValuePair("tz", timezon));
        }
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
        response = httpclient.execute(httppost, res);
        return response;
}

Here it causes problem trying to retrieve large text in String response :

response = httpclient.execute(httppost, res);

I’m storing the response in String. Is that a problem? What is alternative solution of that?

Here is LogCat

09-23 10:07:31.654: INFO/ActivityManager(59): Displayed activity uk.co.dodec.rcgpapp/.SplashScreen: 1267 ms (total 1267 ms)
09-23 10:07:35.854: INFO/dalvikvm-heap(334): Grow heap (frag case) to 3.213MB for 262160-byte allocation
09-23 10:07:38.203: INFO/dalvikvm-heap(334): Grow heap (frag case) to 3.586MB for 524304-byte allocation
09-23 10:07:42.753: INFO/dalvikvm-heap(334): Grow heap (frag case) to 4.336MB for 1048592-byte allocation
09-23 10:07:52.024: INFO/dalvikvm-heap(334): Grow heap (frag case) to 5.836MB for 2097168-byte allocation
09-23 10:08:09.844: INFO/dalvikvm-heap(334): Grow heap (frag case) to 8.836MB for 4194320-byte allocation
09-23 10:08:09.864: INFO/ActivityManager(59): Process com.android.mms (pid 227) has died.
09-23 10:08:45.984: INFO/dalvikvm-heap(334): Forcing collection of SoftReferences for 8388624-byte allocation
09-23 10:08:46.033: ERROR/dalvikvm-heap(334): Out of memory on a 8388624-byte allocation.
09-23 10:08:46.033: INFO/dalvikvm(334): "AsyncTask #1" prio=5 tid=7 RUNNABLE
09-23 10:08:46.033: INFO/dalvikvm(334):   | group="main" sCount=0 dsCount=0 s=N obj=0x43e54fd8 self=0x224d58
09-23 10:08:46.033: INFO/dalvikvm(334):   | sysTid=340 nice=10 sched=0/0 cgrp=bg_non_interactive handle=2248344
09-23 10:08:46.033: INFO/dalvikvm(334):   | schedstat=( 1248172861 2043417240 1093 )
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.util.CharArrayBuffer.expand(CharArrayBuffer.java:~59)
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.util.CharArrayBuffer.append(CharArrayBuffer.java:77)
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.util.EntityUtils.toString(EntityUtils.java:136)
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.util.EntityUtils.toString(EntityUtils.java:146)
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:76)
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
09-23 10:08:46.033: INFO/dalvikvm(334):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
09-23 10:08:46.033: INFO/dalvikvm(334):   at uk.co.dodec.rcgpapp.helper.HttpHelper.getUpdates(HttpHelper.java:172)
09-23 10:08:46.033: INFO/dalvikvm(334):   at uk.co.dodec.rcgpapp.SplashScreen.getUpdate(SplashScreen.java:155)
09-23 10:08:46.033: INFO/dalvikvm(334):   at uk.co.dodec.rcgpapp.SplashScreen$getUpdates.doInBackground(SplashScreen.java:126)
09-23 10:08:46.033: INFO/dalvikvm(334):   at uk.co.dodec.rcgpapp.SplashScreen$getUpdates.doInBackground(SplashScreen.java:1)
09-23 10:08:46.043: INFO/dalvikvm(334):   at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-23 10:08:46.043: INFO/dalvikvm(334):   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-23 10:08:46.043: INFO/dalvikvm(334):   at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-23 10:08:46.043: INFO/dalvikvm(334):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
09-23 10:08:46.043: INFO/dalvikvm(334):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
09-23 10:08:46.043: INFO/dalvikvm(334):   at java.lang.Thread.run(Thread.java:1096)
09-23 10:10:37.353: WARN/dalvikvm(334): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
09-23 10:10:37.375: ERROR/AndroidRuntime(334): FATAL EXCEPTION: AsyncTask #1
09-23 10:10:37.375: ERROR/AndroidRuntime(334): java.lang.RuntimeException: An error occured while executing doInBackground()
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at java.lang.Thread.run(Thread.java:1096)
09-23 10:10:37.375: ERROR/AndroidRuntime(334): Caused by: java.lang.OutOfMemoryError
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.util.CharArrayBuffer.expand(CharArrayBuffer.java:59)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.util.CharArrayBuffer.append(CharArrayBuffer.java:77)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.util.EntityUtils.toString(EntityUtils.java:136)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.util.EntityUtils.toString(EntityUtils.java:146)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:76)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at uk.co.dodec.rcgpapp.helper.HttpHelper.getUpdates(HttpHelper.java:172)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at uk.co.dodec.rcgpapp.SplashScreen.getUpdate(SplashScreen.java:155)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at uk.co.dodec.rcgpapp.SplashScreen$getUpdates.doInBackground(SplashScreen.java:126)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at uk.co.dodec.rcgpapp.SplashScreen$getUpdates.doInBackground(SplashScreen.java:1)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-23 10:10:37.375: ERROR/AndroidRuntime(334):     ... 4 more
09-23 10:10:37.393: WARN/ActivityManager(59):   Force finishing activity uk.co.dodec.rcgpapp/.SplashScreen

I’ve tried following not worked

HttpResponse r = httpclient.execute(httppost);

HttpEntity entity = r.getEntity();

InputStream in = new ByteArrayInputStream(EntityUtils.toByteArray(entity));

File fl = new File(Environment.getDataDirectory().toString() + "/data/" + context.getPackageName() + "/" + FOLDER_NAME);
if(!fl.exists()) fl.mkdir();

String PATH = Environment.getDataDirectory().toString() + "/data/" + context.getPackageName() + "/" + FOLDER_NAME + "/" + "update.xml";
FileOutputStream f = new FileOutputStream(PATH);

byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
    f.write(buffer, 0, len1);
}
f.close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:04:06+00:00Added an answer on May 25, 2026 at 8:04 pm

    That is indeed a problem: don’t do that. You should write the response to a file or parse the stream but definitely don’t try generating a 2.3 MB string. Write a response handler that returns the HttpEntity behind the response, then get the InputStream using the getContent method, then save that to a file and then process the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple web service method that returns a simple java class as
I have a simple mapview that has the following viewdidload method and didupdate to
I've got a simple .NET web service that is supposed to return a string
I've been playing around with Expression Trees. I have the following simple method that
I have the following simple python test script that uses Suds to call a
I am developing an application which connects to the server. By now the login
I want to encapsulate the following query into a method that returns a query
Background: I'm teaching myself about packet sniffing. I run a very simple server in
I am experimenting with fluent extension methods. I have the following simple extension method
I have the following simple methods for writing a python object to a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.