Hi,
I am trying to use a certain wrapper of HttpClient, called HTTPRequestHelper
with an associated responseHandler as the basic class for my wrapper to a web
service which is implemented as a singleton.
HTTPRequestHelper and samples of usage are described in chapter 6 of
"Unlocking Android" published by Manning.
My problem is that invoking both the helper and the handler from a thread
started on the main UI thread (either from an AsyncTask or directly) works
only sporadically.
Here is the basic setup.
public class APIService
{
private ArrayList<Something> myThing;
public ArrayList<Something> getMyThing(params)
{
getTheThing();
return myThing;
}
private void getTheThing()
{
final org.apache.http.client.ResponseHandler<String> responseHandler =
HTTPRequestHelper
.getResponseHandlerInstance(this.theThingHandler);
// prepare params etc...
HTTPRequestHelper helper = new HTTPRequestHelper(responseHandler);
helper.performPost(...);
}
private final android.os.Handler theThingHandler = new Handler()
{
@Override
public void handleMessage(final Message msg)
{
String bundleResult = msg.getData().getString("RESPONSE");
myThing = parseXMLResultForMyThing(bundleResult);
Log.d(myThing); // --------> LOGS PROPERLY myThing!
}
};
}
public class MyActiviy extends Activity
{
private AsyncTask<?, ?, ?> task;
@Override
public void onCreate(Bundle savedInstanceState)
{
task = new getMyThing().execute():
}
private class getMyThing extends AsyncTask<Void, Void, ArrayList<Something>>
{
@Override
protected ArrayList<Something> doInBackground(Void... params)
{
ArrayList<Something> myThing = apiService.getMyThing(other_params);
return myThing;
}
@Override
protected void onPostExecute(ArrayList<Something> result)
{
Log.d(result); // --------> UNFORTUNATELY THE RESULT IS SOMETIMES null
// process(result);
task = null;
}
}
}
So it seems to me that somehow consuming the result of doInBackground begins
before my theThingHandler was able to update the value of myThing in the
APIService.
Any insight of why this is happening and possibly how to fix it would be very
much appreciated.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en