开发者

OutOfMemoryError in Android app when calling a web service

Please, help....

I'm calling 开发者_如何学Goa web service method that return a large soap object and I'm getting the OutOfMemoryException.

How could I avoid that? Is there a way to do that?

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. Best regards, Leonardo


android devices have a very small heap size (about 16MB) and so if your SOAP response returns a lot of data, reading and converting all this data into soap objects can make your device throw the out of memory error.

I faced a similar problem, the easiest approach is to do the following

  1. As your soap response is received, save it as an XML on the disk
  2. then use an XML parser to get whatever data you want out of the XML (create objects or store to a db)

This is how i solved the problem - Very large SOAP response - Android- out of memory error


If you getting a lot of data the best way is using a thread for it. Use a thread with a progress dialog, this will be more friendly to the users that won't have to wait and see that the app is "freezed" or something.

Example (just to show you what I mean, you will have to use it the way you want):

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){} 
}

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜