I want to use async-http-client to post data to a server and keep a SQLite on device in sync with this data. So basically i want the whole thing to:
- Inert new data to the SQLite
- Post the new data to the server using async-http-client
- Update the SQLite row in the onSuccess/onFailure Callbacks with additional data
My Question is: How can i get the right row id in the AsyncHttpResponseHandler?
Lets create an easy example (no database connection to keep it simple but same problem).
private void addPerson(name){
//using a global client created like this in activity onCreate():
//AsyncHttpClient client = new AsyncHttpClient();
//here is a database insert creating a new row, returning the inserted id
int rowId = <some id returned by the insert>;
RequestParams param = new RequestParams();
param.put("name", name);
client.post("http://www.my.service.url", param, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
//The response i get contains an additional value, lets say userkey. I want to update the right database row with that information.
//How to get the right rowId here?
}
});
}
So what is the best way to achieve this? Overriding AsyncHttpResponseHandler to somehow add a parameter to the callback functions?
Make your variable final, like