Question

I'm running the Jsoup.connect().get in an Asynctask to prevent network on main thread but this method also blocks the UI because of the get(). Any suggestions to prevent or maybe minimize the blocking?

@Override
protected Document doInBackground(String... strings) {
    Document doc = null;
    try {
        doc = Jsoup.connect(strings[0]).get();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return doc;
}
Was it helpful?

Solution

From your comments you have

 task.execute(url).get();

to

task.execute(url);

Calling get does not make it Asynchronous any more. It will wait for the result blocking the ui thread. Just use .execute

http://developer.android.com/reference/android/os/AsyncTask.html

public final Result get ()

Added in API level 3
Waits if necessary for the computation to complete, and then retrieves its result.

Returns
The computed result.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top