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?
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