I’m having problems trying to find the best way to do two-way server communications, asynchronously. I am able to do the server communications hard coded to a server (no encapsulation, async calls), but I want to know what the best way to do it is. There’s a protocol for logging in, registering, changing location, etc.
The server communications are using JSON and HTTPPost. The app would be sending JSON data and receiving it and putting it into a database.
I thought of making a ServerCommuncations class which holds data such as username, password, etc. and instantiates the HTTPRequest objects and other common objects. This could be inside a Bound service.
Now I could use a Bound Service with an AsyncTask, however multiple Activities in the app will need to do server communications so it would mean binding the service to multiple Activities.
- Is this possible?
- Is there a better way?
- If I was to use the bound service, would it be best to use Messengers or extend Binder class?
What are your thoughts?
A possibility is to use IntentService for handling asynchronous code.