Http url connection ?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Http url connection ?

Postby JamesAndroid » Fri Dec 11, 2009 5:08 am

Hi guys.

I am searching about Http URL connection.
IFAIK, in order to create Http connection needs to run separate Thread for Blackberry.

Like this, Do I need to create Thread for http connection on Android?

Can you help me about it ?

I've searched sample code and tried it. But it is very difficult to understand.

Thanks in advance.
JamesAndroid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Dec 07, 2009 7:23 am

Top

Postby stifry » Fri Dec 11, 2009 9:09 pm

You'll want to run it in a separate thread in Android as will so that it doesn't block.

Here's an example of parsing XML from a URL:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                        URL url = new URL("http://www.somewebsite.com/query");
  3.  
  4.  
  5.  
  6.                        SAXParserFactory spf = SAXParserFactory.newInstance();
  7.  
  8.                        SAXParser sp = spf.newSAXParser();
  9.  
  10.  
  11.  
  12.                        /* Get the XMLReader of the SAXParser we created. */
  13.  
  14.                        XMLReader xr = sp.getXMLReader();
  15.  
  16.                        /* Create a new ContentHandler and apply it to the XML-Reader*/
  17.  
  18.                        Weather weather = new Weather();
  19.  
  20.                        xr.setContentHandler(weather);
  21.  
  22.                        
  23.  
  24.                        /* Parse the xml-data from our URL. */
  25.  
  26.                        xr.parse(new InputSource(url.openStream()));
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Jeff
Visit Trackaroo.com!
Trackmaster - Motorsports Lap Timer
Dynomaster - Performance Dyno
Image Image
User avatar
stifry
Developer
Developer
 
Posts: 46
Joined: Tue Feb 17, 2009 7:50 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests