异步加载AsyncTask
Posted 巫山老妖
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异步加载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");
}
以上是关于异步加载AsyncTask的主要内容,如果未能解决你的问题,请参考以下文章
android AsyncTask异步加载的图片怎么设置点击放大再点还原啊?????????
AsyncTask异步加载和HttpURLConnection网络请求数据