I need to get data from a server via a php script I'm using an AsyncHttpClient and an AsyncHttpResponseHandler from the loopj library.
public void buttonListener (View view) {
if (view.getId() == R.id.button) {
//start loading...
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://host.com/data.php", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
//loading succeeded
//now I can parse the byte[] responseBody to a JSONObject...
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
//loading failed
}
});
//I want my program to stop at this point until onSuccess() or onFailure() is called
}
}
At the described point in my program I want to wait until the server does response. I found some examples using Threads
and the methods wait()
and notifyAll()
but I've no idea how to use them in my situation.
Can anybody help me?
THX