1

このコードは2.2エミュレーター(API 8)では正常に機能しますが、4.1エミュレーター(API 16)では機能しません。何か案が?

すべての回答と関心をありがとう

   `try 
    {   
        String url = "http://10.0.2.2:8080/cofradeapps/static/hermandades.xml";
        urlHermandades = new URL(url);
        HttpURLConnection urlConnection = (HttpURLConnection) urlHermandades.openConnection();  
        InputStream in = urlConnection.getInputStream();
        return in;
    } 
    catch (IOException e) 
    {
        throw new RuntimeException(e);
    }
4

1 に答える 1

0

新しいバージョンの Android では、UI スレッドでネットワーキングを行うことはできません。別のスレッド (おそらく ASyncTask) を使用する必要があります。

private class YourClass extends AsyncTask<URL> {
     protected String doInBackground(URL... urls) {

         //Do your stuff here

     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     } 

     protected void onPostExecute(Long result) {
         //When you're finished update the UI thread with your results
     }
}
于 2013-01-30T16:34:10.857 に答える