zoukankan      html  css  js  c++  java
  • 异步加载AsyncTask

    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");
            
            
            
            
        }

  • 相关阅读:
    你必须知道的.Net 8.4.4 位枚举
    你必须知道的.Net 8.2.3 覆写 Equals
    你必须知道的.Net 8.2.2 本质分析
    【日 志】
    你必须知道的.Net 【特 性】Attribute
    【GC】
    用vhd挂载并安装win7且建立分差vhd
    让win7安装时出现版本选项
    vdi、vhd、vmdk虚拟格式转换
    移动硬盘/U盘上装Windows 7旗舰版(VHD版)
  • 原文地址:https://www.cnblogs.com/changyiqiang/p/6001488.html
Copyright © 2011-2022 走看看