zoukankan      html  css  js  c++  java
  • AsyncTask异步任务类使用学习

    new MyAsyncTask()
    .execute("http://pic.baike.soso.com/p/20120716/bki-20120716095331-640956396.jpg");

    class MyAsyncTask extends AsyncTask<String, Void, Bitmap> {
    @Override
    protected void onPreExecute() {
    // TODO 自动生成的方法存根
    super.onPreExecute();
    dialog.show();

    }

    @Override
    protected Bitmap doInBackground(String... params) {

    Bitmap bitmap = null;
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpPost = new HttpGet(params[0]);
    try {
    HttpResponse respon = httpClient.execute(httpPost);

    if (respon.getStatusLine().getStatusCode() == 200) {
    HttpEntity entity = respon.getEntity();
    byte[] data = EntityUtils.toByteArray(entity);
    bitmap = BitmapFactory
    .decodeByteArray(data, 0, data.length);

    }
    else {
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    return bitmap;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
    // TODO 自动生成的方法存根
    super.onPostExecute(result);
    imageView.setImageBitmap(result);
    dialog.dismiss();

    }

    }

  • 相关阅读:
    AJAX基础
    DOM事件机制(事件捕获和事件冒泡和事件委托)
    http协议
    DOM实战-js todo
    python常见面试题
    jQuery快速入门
    三级菜单
    购物车
    员工信息表
    random模块
  • 原文地址:https://www.cnblogs.com/lzh-Linux/p/4584095.html
Copyright © 2011-2022 走看看