-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Using AsyncHttpClient from an IntentService #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm trying to use SyncHttpClient inside the intent service.. but I'm still getting this error even using SyncHttpClient. I'm using the latest from master branch ( built a jar today).
|
This should be fixed by merge #492 |
I was able to get it to work with the latest version. In some cases I did need to call Looper.prepare() before making the async request. |
Yes, there was another recent fix of Looper problem, see 989b35a Thank you for testing, closing as solved |
The latest changes in the past week have now broken this... inside an intent service I can't make calls to AsyncHttpClient, I get the following exception: It was working properly with the snapshot about a week ago. This is wit the latest as of today:
|
I am also getting this:
|
Is it hard to read the error message You should create your response handler in a looper thread or use SyncHttpClient instead. ? |
Is there any sample code with that ? I read the Service sample but it's using SyncHttpClient... |
Yes, it is, see the file: ExampleIntentService.java and the Activity context for that sample, IntentServiceSample.java |
Error message say itself solution "user You should create your response handler in a looper thread or use SyncHttpClient instead." |
@dhams correct, thanks |
Sorry to dig into this old issue. I called AsyncHttpClient from a IntentService thread, if the client is initialized by new AsyncHttpClient, the response handler only executes onPreProcessResponse() callback, no onStart, onFinish, neither onSuccess nor onFailure. I was stuck by this problem and had a very long-time (few hours) search and finally saw this, my luck. After I change the client object to a new SyncHttpClient, then all callback are executed in the correct order, but the request will be blocked after the response has been handled. My question is can I still alternate to use AsyncHttpClient with non-blocking behavior in an intent service? Sorry if it's a silly question. |
@tedyyu The issue with using AsyncHttpClient insider IntentService is quite visible to me . IntentService manages queue of background thread and AsyncHttpClient is run itself in the thread so ultimatily you are calling thread insider the thread. |
I was using 1.4.6 with both asynchronous and synchronous calls from a thread.
Then I have overridden the method mentioned in the answer below and all started to work. |
In 1.4.6, you can create ResponseHandler with a Looper param...I don't think you need to override the method to make it work. |
I'm using AsyncHttpClient in a large Android project-- it works great in most cases, except when we need to make network calls from an Intent Service.
In this case-- we actually need to make a synchronous network call but the library doesn't make it easy to do that.
Also, we use session cookies with our AsyncHttpClient-- we create a static AsyncHttpClient instance and it's used throughout the project, and since we have a session cookie, this is preserved.
So I guess there are two potential solutions:
Need a way to create a SyncHttpClient from an instance of AsyncHttpClient so session cookies are preserved
Need a way to reliably use AsyncHttpClient in an IntentService
I know some other people have had issues with using this library in an IntentService-- how have you solved it?
The text was updated successfully, but these errors were encountered: