0

I am creating a android app that uses a TCP socket to connect to a server. It continuously receives xml strings from this socket and I need to parse it as it comes. Currently I've implemented the socket in a service in the same process of the application.

I get outofmemory exception sometimes. The xml strings I receive will be around 1-3mb. My question is, will it be more efficient if a run my service in a separate process as my socket constantly needs to work? What is the best way to implement a socket in android which works the app life span?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
blessanm86
  • 31,439
  • 14
  • 68
  • 79

1 Answers1

0

You should definitely put your socket in a thread. If it's not the case you take the chance to freeze the entire application on network timeout for example.

There is several different way to make a thread in android. My favorite is to create a class which extends Thread.

have a look to the painless threading in android doc and the more general Processes and Threading article

grunk
  • 14,718
  • 15
  • 67
  • 108
  • My socket is in another thread in the service. But the thing is my socket is taking a bit of resources as I am parsing the response. So I considered another process to get another memory heap. – blessanm86 Aug 13 '11 at 07:25
  • Also the class/tool you're using to parse XML can have much influence on memory usage, regarding if it's event-based (light) or tree-based (heavy, has to be loaded completely), how are you doing that? – darma Aug 13 '11 at 10:36
  • @darma I am using the SaxParser. – blessanm86 Aug 13 '11 at 11:12