Need an example showing how to execute asynchronous HTTP requests

I use a web service, so I want to use an asynchronous thread to request HTTP authentication, and another thread later to make additional service requests while my main thread is running.

I would like to see a good example of how to do this and how to show downloaded messages in some way in the main application. How does the main application know when the thread is completed? And what if my thread encounters exceptions, how can I handle this?

HTTP requests are sent later, use the same cookie settings with the first auth request, so that subsequent requests will receive the same cookies and just work?

+6
android multithreading asynchronous task
source share
3 answers

Look here. How do I execute a web request in my thread?

+5
source
+6
source

The AndroidAsync library that I wrote to handle this automatically will run in the background and re-reference the user interface thread:

https://github.com/koush/AndroidAsync

// url is the URL to download. The callback will be invoked on the UI thread // once the download is complete. AsyncHttpClient.getDefaultInstance().get(url, new AsyncHttpClient.StringCallback() { // Callback is invoked with any exceptions/errors, and the result, if available. @Override public void onCompleted(Exception e, String result) { if (e != null) { e.printStackTrace(); return; } System.out.println("I got a string: " + result); } }); 
+1
source

All Articles