-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Run on current thread if no looper is present in Async response #492
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
Run on current thread if no looper is present in Async response #492
Conversation
印象笔记无法提交笔记,原因如下: 本月帐户上传流量已经达到上限。 原消息详情: 为了防止邮件过多,接下来的360分钟内,你将不会收到报错回复。 升级到印象笔记高级帐户,可以发送的邮件数量将从50封提升到200封。
|
@@ -30,6 +30,8 @@ | |||
import org.apache.http.client.HttpResponseException; | |||
import org.apache.http.util.ByteArrayBuffer; | |||
|
|||
import com.heyzap.http.AsyncHttpResponseHandler.ResponderHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean com.loopj.http.AsyncHttpResponseHandler.ResponderHandler;
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it when Eclipse does that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
印象笔记无法提交笔记,原因如下:
本月帐户上传流量已经达到上限。
原消息详情:
来自:Daniel Rhodes <notifications@github.com>
发送到:gongzunpan.e099425@m.yinxiang.com
全部收件人:loopj/android-async-http <android-async-http@noreply.github.com>; zunpan <gongzunpan@gmail.com>
主题:Re: [android-async-http] Run on current thread if no looper is present in Async response (#492)
为了防止邮件过多,接下来的360分钟内,你将不会收到报错回复。
升级到印象笔记高级帐户,可以发送的邮件数量将从50封提升到200封。
https://app.yinxiang.com/Checkout.action?origin=email%2Dcommerce
- 印象笔记团队
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this allow me to make async-http calls from within an AsyncTask<..>,
specifically the doInBackground(..) function?
One issue I have is I'm migrating an existing project that uses AsyncTasks
everywhere to do lots of networking calls + other background stuff like
user authentication with Google+.
In doing the migration, I'm trying to keep some of the functionality in the
existing AsyncTask implementations-- but as it stands now I can't make
calls to async-http from within an async task.
On Fri, Mar 14, 2014 at 10:23 AM, Daniel Rhodes notifications@github.comwrote:
In
library/src/main/java/com/loopj/android/http/AsyncHttpResponseHandler.java:@@ -30,6 +30,8 @@
import org.apache.http.client.HttpResponseException;
import org.apache.http.util.ByteArrayBuffer;+import com.heyzap.http.AsyncHttpResponseHandler.ResponderHandler;
I love it when Eclipse does that.
Reply to this email directly or view it on GitHubhttps://github.com//pull/492/files#r10617406
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
印象笔记无法提交笔记,原因如下:
本月帐户上传流量已经达到上限。
原消息详情:
来自:Suneet Shah <notifications@github.com>
发送到:gongzunpan.e099425@m.yinxiang.com
全部收件人:loopj/android-async-http <android-async-http@noreply.github.com>; zunpan <gongzunpan@gmail.com>
主题:Re: [android-async-http] Run on current thread if no looper is present in Async response (#492)
为了防止邮件过多,接下来的360分钟内,你将不会收到报错回复。
升级到印象笔记高级帐户,可以发送的邮件数量将从50封提升到200封。
https://app.yinxiang.com/Checkout.action?origin=email%2Dcommerce
- 印象笔记团队
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely. Without this change, here is what is happening:
- You make request on your own thread.
- Http Async library uses its own thread to make the request.
- It tries to run the callback on original thread. Sees it is gone, and bails.
This can be mitigated by starting a looper which keeps your original thread alive (and thus the handler can execute the Runnable).
In my change, if the original thread is gone, it executes the callback on the HTTP thread. So in your AsyncTask thing, it would likely do the same thing. Try it out.
@danielrhodes I believe your case is a rare one, why not just override that particular method and create your own response handler? Cleaner, I think, and would better suite your specific needs. |
I like the change, thank you |
The implementation before essentially means that you can't use this library from short-lived threads. It also starts a looper on a thread not owned by the HTTP library, which is unexpected.
The following fix does the following: