码迷,mamicode.com
首页 > 其他好文 > 详细

异步加载AsyncTask

时间:2016-10-26 19:26:57      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:int   .exe   nec   cat   any   des   back   end   adl   

private void huodeshuju() {
        new AsyncTask<String, Void, String>() {

            @Override
            protected String doInBackground(String... params) {
                try {
                    URL url=new URL(params[0]);
                    HttpURLConnection urlConnection=(HttpURLConnection) url.openConnection();
                    urlConnection.setConnectTimeout(5000);
                    urlConnection.setReadTimeout(5000);
                    urlConnection.setRequestMethod("GET");                  
                    int code=urlConnection.getResponseCode();                    
                    if (code==200) {
                        InputStream inputStream=urlConnection.getInputStream();
                        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream));
                        String line;
                        StringBuffer buffer=new StringBuffer();
                        while ((line=bufferedReader.readLine())!=null) {
                            buffer.append(line);
                            
                        }
                        String str=buffer.toString();
                        
                       /* Message message=new Message();
                        message.what=1;
                        message.obj=str;
                      //发送Handler消息
                        handler.sendMessage(message);*/
                        
                       return str;
                    }
                    
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
           
                return null;
            }
            
            
            protected void onPostExecute(String result) {
                
                tojson(result);
            };
            
            
        }.execute("http://i.dxy.cn/snsapi/home/feeds/list/all?sid=4df0360f-2a20-4198-beb8-4dc5660c4f08&u=zhetianyishou&s=10&mc=0000000049029dcaffffffff99d603a9&token=TGT-13165-buaw5fHpqLlefw9bSOB0oF41fobaV4rMZmK-50&hardName=iToolsAVM_T0008098S&ac=4124c5f1-2029-4fda-b06f-a87ac5ad8d11&bv=2013&vc=6.0.6&tid=c25e673d-e82a-4e46-bd4e-c1e86d497126&vs=4.4.4&ref_tid=54720e1a-7eed-4993-9f51-3d760f3d0b2e");
        
        
        
        
    }

异步加载AsyncTask

标签:int   .exe   nec   cat   any   des   back   end   adl   

原文地址:http://www.cnblogs.com/changyiqiang/p/6001488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!