• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 4518
572
VSCode 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: 43081
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.
reply
    Bookmark Topic Watch Topic
  • New Topic