Skip to content

BinaryHttpResponseHandler inside run() method #441

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

Closed
vishwasdoth opened this issue Jan 31, 2014 · 10 comments
Closed

BinaryHttpResponseHandler inside run() method #441

vishwasdoth opened this issue Jan 31, 2014 · 10 comments
Assignees
Labels
Milestone

Comments

@vishwasdoth
Copy link

I am using BinaryHttpResponseHandler inside run method for multiple image download. I was using this in 1.4.1 and was working without any issues. Just got new version of loopj and encounter this issue. Though I am able to call BinaryHttpResponseHandler independently successfully but when I call in inside run method it does nothing. It doesn't show any error or exception. it simply goes dead when reaches to

    httpClient.get(imageInfo.imageUrl, null, new     BinaryHttpResponseHandler()

    run(){
    httpClient.get(imageInfo.imageUrl, null, new BinaryHttpResponseHandler() {

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {

                        Log.i(TAG, "Remote success");
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, byte[] responseBody, final Throwable error) {
                        Log.i(TAG, "Remote failure");
                    }


                });
    }
@vishwasdoth
Copy link
Author

Guys,
Please help me with this I am stuck. Let me know what I am doing wrong here.

@vishwasdoth
Copy link
Author

See if this helps you guys to understand the problem

    private class DownloaderThread extends Thread {

            public void run() {

                // continue downloading while not shutdown
                while (somecondition) {

                                    //It simply get dead here
                    httpClient.get(imageUrl, null, new BinaryHttpResponseHandler() {

                        @Override
                        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {}

                        @Override
                        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, final Throwable error) {}

                    });
                }
            }
        }
  • No Exception or Error
  • on Debug this this how it goes

F5-httpClient.get
-- public BinaryHttpResponseHandler() {
F5 super();
}
--- public AsyncHttpResponseHandler() {
// Init Looper by calling postRunnable without argument
F5 postRunnable(null);
}
----protected void postRunnable(Runnable runnable) {
boolean missingLooper = null == Looper.myLooper();
if (missingLooper) {
Looper.prepare();
}
if (null == handler) {
handler = new ResponderHandler(this);
}
if (null != runnable) {
handler.post(runnable);
}
if (missingLooper) {
//IT COMES TILL THIS POINT AND GOES DEAD
Looper.loop();
}
}

@vishwasdoth
Copy link
Author

Anyone can help me in this?

@Osram-Lux
Copy link

Hi,
Call:
httpClient.get(imageUrl, null, new BinaryHttpResponseHandler() ……
directly on the UI thread (i.e. do not create a thread for the call above). Asynch Http does the http communication on its own background thread. This also has the benefit that the onXXXXX callbacks will run on the UI thread. which is most probably what you want anyway.

Disclaimer: I have only been using the JSonHttpResponseHandler, so i have no experience with issues that the BinaryHttpResponseHandler().
/BR
Jan Lindåker

jan.lindaker@commind.se | +46 706 66 52 08 | Skype: jan_lindaker | MEC Stora Varvsgatan 6a, 211 19 Malmö, Sweden

On 9 feb 2014, at 21:17, vishwasdoth notifications@github.com wrote:

Anyone can help me in this?


Reply to this email directly or view it on GitHub.

@vishwasdoth
Copy link
Author

Thanks for your suggestion.

I am downloading multiple images and using semaphore to control permits
(new Semaphore(maxParallelDown, true);). I don't know how to achieve same with AsyncTask or any other way. Could you please suggest?

Thanks.

@Osram-Lux
Copy link

The package already uses a thread pool for the callbacks, so you do not need to set up your own (possibly you may need to investigate how to adjust the number of threads).

jan.lindaker@commind.se | +46 706 66 52 08 | Skype: jan_lindaker | MEC Stora Varvsgatan 6a, 211 19 Malmö, Sweden

On 10 feb 2014, at 08:33, vishwasdoth notifications@github.com wrote:

Thanks for your suggestion.

I am downloading multiple images and using semaphore to control permits
(new Semaphore(maxParallelDown, true);). I don't know how to achieve same with AsyncTask or any other way. Could you please suggest?

Thanks.


Reply to this email directly or view it on GitHub.

@vishwasdoth
Copy link
Author

Isn't it same issue #397 where you have also done quite a good investigation. This issue seems very much related to #397.

@smarek smarek added this to the 1.4.5 milestone Feb 18, 2014
@smarek smarek self-assigned this Feb 18, 2014
@fineswap fineswap reopened this Apr 29, 2014
@gongzunpan
Copy link

印象笔记无法提交笔记,原因如下:

本月帐户上传流量已经达到上限。

原消息详情:
来自:Noor Dawod <notifications@github.com>
发送到:gongzunpan.e099425@m.yinxiang.com
全部收件人:loopj/android-async-http <android-async-http@noreply.github.com>
主题:Re: [android-async-http] BinaryHttpResponseHandler inside run() method (#441)

为了防止邮件过多,接下来的360分钟内,你将不会收到报错回复。

升级到印象笔记高级帐户,可以发送的邮件数量将从50封提升到200封。
https://app.yinxiang.com/Checkout.action?origin=email%2Dcommerce

  • 印象笔记团队

@smarek smarek removed the wontfix label May 2, 2014
@asebak
Copy link

asebak commented May 4, 2014

I am having the exact same problem as vishwasdoth and it doesn't matter if you just run it on the ui thread or the way he stated it here. The AsyncHttpresponsehandler and JsonHttpresponsehandler work fine but whenever I use the BinaryHttpResponseHandler no exceptions get raised, the program just crashes completely right after the get request.

@fineswap
Copy link
Contributor

fineswap commented May 4, 2014

@vishwasdoth
This should be already fixed in master branch.
Please pull latest master branch and compile against it, post your findings here.

@vishwasdoth
Copy link
Author

I manage to solve it. I simply omitted my own thread creation and ran it on UI thread itself. It worked. Anyway thanks for info.

@fineswap fineswap closed this as completed May 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants