1

I am making a network app that works with a few news sites. I have an option to view and download articles (for reading in future). There is no fast mobile internet in my country (mostly 2G with the speed up to 15 KB/sec) and my app doesn't work really well with the slow connect though it's perfect with fast connection. As I have seen from logs it can't establish the connection. When I try to open the article it doesn't load at all or goes into infinite loading. When I try to save the article it simply saves the blank file. How can I track these mistakes and catch them? And what are the correct ways of handling it?

I suppose that my code is irrelevant as it works correctly with Wi-fi. I think I simply need to add lines, not to edit them

Vendetta8247
  • 592
  • 1
  • 5
  • 30
  • I believe you can set the timeout somewhere in Jsoup. – Jonas Czech Apr 29 '15 at 18:33
  • @JonasCz yes, there is a timeout in JSoup. And I use it. But I still get an exception. And I would also love to know how to handle it with WebView – Vendetta8247 Apr 29 '15 at 19:29
  • 1
    You could you try some other way to get the data from the internet as a `String`, and then have Jsoup parse that `String` instead of downloading the HTML itself. You could use Android's built in `HttpUrlConnection`, or [OkHttp](http://square.github.io/okhttp/), which is more reliable, and esier to use. I wrote a similar app, and I used a combination of OkHttp to download and Jsoup to parse, and this works very well for me. For WebView, check [this](http://stackoverflow.com/a/22620404/4428462), i've never tried it, so not sure if it works. – Jonas Czech Apr 29 '15 at 19:39
  • @JonasCz thank you very much for a detailed comment. But how is loading text is different from parsing HTML? Isn't it the same process? HTML is basically a sequence of characters so parsing it might be the download itself. Unluckily, my project is in a pretty close-to-release stage and the problem I'm facing is actually not essential but I would like to fix it without changing the project much. – Vendetta8247 Apr 29 '15 at 23:38
  • What Jsoup does is to download the HTML first, and then parse it. The problem is that Jsoup (or rather the standard Java apis it uses) is not very reliable with downloading HTML (especially on a bad network connection), and so it never gets to the parsing stage. My idea is to download the HTML as text first, and then parse the downloaded text / HTML with Jsoup. – Jonas Czech Apr 30 '15 at 06:47

1 Answers1

0

ok, you need to manage the information very good, you need define the package size to download, you need a webservices that allow to you to manage the information one by one, for example you need design packages no more than 500kb size to download, when this package is downloaded you can show something in your mobile and continue downloading the next package in background.

500kb is only an example you need to test what is the maximum data size to download and create packages like that in your web services

toddsalpen
  • 411
  • 4
  • 9
  • That is a good idea, thank you very much. But I think it's not my thing. It doesn't connect at all I think. It isn't dropping the connection. It just maybe is too slow to connect at all (or to Android identify that there is a connection at all :-) ) – Vendetta8247 Apr 29 '15 at 19:28
  • if your problem is about the connection then you can read about best practices for requests – toddsalpen Apr 29 '15 at 20:32