OutOfMemoryError in an Android app when calling a web service

Please, help....

I call a web service method that returns a large soap object, and I get OutOfMemoryException.

How could I avoid this? Is there any way to do this?

SoapSerializationEnvelope envelope = new    SoapSerializationEnvelope(SoapEnvelope.VER11);           
envelope.dotNet=true;  
envelope.setOutputSoapObject(request);  
try  {     
    httpTransport.call(SOAP_ACTION, envelope);// Here I am getting error 
}   
catch(Exception e){} 

I appreciate any help. Regards, Leonardo

+3
source share
2 answers

Android devices have a very small heap size (about 16 MB), so if your SOAP response returns a lot of data, reading and converting all this data to soap objects can cause your device to throw an error from memory.

I ran into a similar problem, the easiest way is to do the following

  • Since your response to the soap is received, save it as XML to disk
  • XML , XML ( a db)

- SOAP - Android-

+1

, - . , , , "" - .

( , , , ):

public class YourActivity extends Activity implements Runnable {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    // Your code...
    SoapSerializationEnvelope envelope = new    SoapSerializationEnvelope(SoapEnvelope.VER11);           
    envelope.dotNet=true;  
    envelope.setOutputSoapObject(request); 

    // Running the thread
    Thread thread = new Thread(this);
    thread.start();
}

@Override
public void run() {
    try  {     
        httpTransport.call(SOAP_ACTION, envelope);// Here I am getting error 
    }   
    catch(Exception e){} 
}

!

0

All Articles