If I understand, you need a Webservice to communicate with your app and it'll be like:
Your app calls your WS url (maybe with some POST datas) and your WS responds to your app.
Then, you can make a REST Webservice that communicates in JSON? Android can parse JSON with some very good libraries like Google GSON for example.
For the WS technology you can use whatever you want.
The things will work like, you ask for an object, lets say it's a list of people with an age and a name. The API is at http://www.yourapi.com/
, so as you're asking for people, it's http://www.yourapi.com/people
When you call the API, the response is like:
[{
"age": 18,
"name": "toto"
},
{
"age": 21,
"name": "foo"
}]
So, from a client side (your Android project), you have a Person
class: Person.java
public class Person {
private int age;
private String name;
public Person(){
this.age = 0;
this.name = "";
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
public String getName({
return name;
}
public void setName(String name){
this.name = name;
}
}
Which is your model, and an AsyncTask
to download it:
public abstract class PeopleDownloader extends AsyncTask<Integer, Integer, ArrayList<Person>> {
private static final String URL = "http://www.yourapi.com/people";
@Override
protected ArrayList<Person> doInBackground(Void... voids) {
HttpClient httpclient = new DefaultHttpClient();
// Prepare a request object
HttpGet httpget = new HttpGet(URL);
// Execute the request
HttpResponse response;
try {
Log.d(TAG, "Trying to reach " + httpget.getURI());
response = httpclient.execute(httpget);
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String finalResposne = "";
String line = "";
while ((line = rd.readLine()) != null) {
finalResposne += line;
}
Log.d(TAG, finalResposne);
return new Gson().fromJson(finalResposne, new TypeToken<List<Person>>() {
}.getType());
} catch (Exception e) {
Log.e(TAG, "Error in doInBackground " + e.getMessage());
}
return null;
}
}
And it's done.