This week's book giveaway is in the Design forum.
We're giving away four copies of Experimentation for Engineers: From A/B testing to Bayesian optimization and have David Sweet on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

To make downloaded webpage source to work, requires a minimal SDK version 3 but other existing funct

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to download a web page source within android using Java, but elsewhere in my program the minimum requirement for SDK within the Android manifest needs to be set at 11 but the below code (to download source) will only work when the minimum SDK version is set to 3.

Is there any changes you would suggest I make to the below code



Code above requires minimum SDK version 3

Rest of code requires minimum SDK version 1


When I change the minimum SDK in android manifest to 11 above code won't work


(By won't work, I mean I get the error "Unfortunately Test has stopped" and then the app closes)
 
Marshal
Posts: 4174
555
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did it die with a NetworkOnMainThreadException exception? This was introduced in API 11.
 
Andrew Tyrer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More than likely. When I use it with a minimum SDK set to 11, the described error occurs



What is the fix for this? Is there another method which actually works?
 
Rancher
Posts: 43076
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fix is not to do network I/O on the UI thread. I generally use an AsyncTask for network activity.

Should the issue mentioned by Ron turn out to be the culprit, you may want to enter StrictMode in all your Android apps to warn you in case the app does something it should not.

Also note that while generally Android is backwards compatible, sometimes new versions show different behavior. See http://developer.android.com/about/versions/android-4.4.html#Behaviors, http://developer.android.com/about/versions/android-4.3.html#Behaviors and http://developer.android.com/about/versions/android-4.2.html#Behaviors for recent examples.
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic