How to use Jsoup with Volley?

Adrian Ivasku

I have a working example with Jsoup and AsyncTask, and that works fine. I am just not satisfied with the performance. It takes 3-6 seconds to load a simple list page with text and images.

I want to boost the performance somehow... so I have stumbled on volley.

Can anyone explain hot to use volley with jsoup?

I use this to get the doc object that holds the particular URL:

 public Document GetDocument(String site) {      
        Document doc = Jsoup.connect(site).timeout(600000)
        .data("query", "Java")
        .userAgent("Mozilla")
        .get();

        return doc;
 }

I guess I would only analyze the data with jsoup and connect/download with volley? Whene I use Jsoup.connect(site).timeout(600000) I should do that with volley ?

Can anyone write/link a simple example using volley and jsoup?

Stephan

Can anyone write/link a simple example using volley and jsoup?

Under the hood, Jsoup make use of HttpUrlConnection. This class has known unresolved issues, bugs and performance issues on the Android Platform.

Instead, load the data with Volley first then parse it with Jsoup.

Sample Code:

private static RequestQueue myRequestQueue = null;

public Document GetDocument(String site) throws Exception {   
   final Document[] doc = new Document[1];
   final CountDownLatch cdl = new CountDownLatch(1);
 
   StringRequest documentRequest = new StringRequest( //
        Request.Method.GET, //
        site, //
        new Response.Listener<String>() {
           @Override
           public void onResponse(String response) {
               doc[0] = Jsoup.parse(response);
               cdl.countDown();
           }
        }, //
        new Response.ErrorListener() {
           @Override
           public void onErrorResponse(VolleyError error) {
               // Error handling
               System.out.println("Houston we have a problem ... !");
               error.printStackTrace();
           }
        } //
   );

   if (myRequestQueue == null) {
       myRequestQueue = Volley.newRequestQueue(this);
   }

   // Add the request to the queue...
   myRequestQueue.add(documentRequest);

   // ... and wait for the document.
   // NOTE: Be aware of user experience here. We don't want to freeze the app...
   cdl.await();

   return doc[0];
}

References

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use Jsoup with Volley?

From Dev

How to use Stetho with Volley?

From Dev

Confused on how to parse HTML with Jsoup after making volley StringRequest

From Dev

How to use ImageLoader of Volley Library?

From Dev

how to use jsoup on router address?

From Dev

How to Use Link in website with JSOUP?

From Java

How do you use the Android Volley API?

From Dev

How to use Jsoup to login my university website?

From Dev

How to use Jsoup get repeating number?

From Dev

How to use JSoup to grab a specific value?

From Dev

How do I use the Volley network request queue?

From Dev

How to use Android Volley GET method with specified parameter?

From Dev

How to use network frameworks (volley , okhttp , etc) in libgdx?

From Dev

Volley use in android program

From Dev

why to use volley or picasso

From Dev

How to use JSoup to get web page by sending a specific date?

From Dev

How to use jSoup to grab text from <pre> field and keep formatting

From Dev

How to automate Gmail Login to use HttpsURLConnection and Jsoup in Java 8

From Dev

How to use Jsoup to get href link without the extra characters?

From Dev

How to perform loop with volley

From Dev

How to replace Hurlstack for Volley?

From Dev

What is the use of Volley API in android?

From Dev

jsoup - How to extract this image using Jsoup?

From Dev

How to show background image in list view via parsing json data with use of volley while image is not loaded

From Dev

Android: how to use Code to interface design pattern to have multiple implementations of network call libraries(Retrofit or volley)

From Dev

How to fetch frames with Jsoup?

From Dev

How to integrate Jsoup with WebDriver?

From Dev

JSOUP: How to get Href?

From Dev

How to fill a form with Jsoup?

Related Related

  1. 1

    How to use Jsoup with Volley?

  2. 2

    How to use Stetho with Volley?

  3. 3

    Confused on how to parse HTML with Jsoup after making volley StringRequest

  4. 4

    How to use ImageLoader of Volley Library?

  5. 5

    how to use jsoup on router address?

  6. 6

    How to Use Link in website with JSOUP?

  7. 7

    How do you use the Android Volley API?

  8. 8

    How to use Jsoup to login my university website?

  9. 9

    How to use Jsoup get repeating number?

  10. 10

    How to use JSoup to grab a specific value?

  11. 11

    How do I use the Volley network request queue?

  12. 12

    How to use Android Volley GET method with specified parameter?

  13. 13

    How to use network frameworks (volley , okhttp , etc) in libgdx?

  14. 14

    Volley use in android program

  15. 15

    why to use volley or picasso

  16. 16

    How to use JSoup to get web page by sending a specific date?

  17. 17

    How to use jSoup to grab text from <pre> field and keep formatting

  18. 18

    How to automate Gmail Login to use HttpsURLConnection and Jsoup in Java 8

  19. 19

    How to use Jsoup to get href link without the extra characters?

  20. 20

    How to perform loop with volley

  21. 21

    How to replace Hurlstack for Volley?

  22. 22

    What is the use of Volley API in android?

  23. 23

    jsoup - How to extract this image using Jsoup?

  24. 24

    How to show background image in list view via parsing json data with use of volley while image is not loaded

  25. 25

    Android: how to use Code to interface design pattern to have multiple implementations of network call libraries(Retrofit or volley)

  26. 26

    How to fetch frames with Jsoup?

  27. 27

    How to integrate Jsoup with WebDriver?

  28. 28

    JSOUP: How to get Href?

  29. 29

    How to fill a form with Jsoup?

HotTag

Archive