zoukankan      html  css  js  c++  java
  • andriod多线程

    用ThreadHandle可以实现多线程,然后再主线程更新UI

    第二种就是用 

    AsyncTask

    具体看代码

    public void onClick(View v) {
        new DownloadImageTask().execute("http://example.com/image.png");
    }
    
    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        /** The system calls this to perform work in a worker thread and
          * delivers it the parameters given to AsyncTask.execute() */
        protected Bitmap doInBackground(String... urls) {
            return loadImageFromNetwork(urls[0]);
        }
        
        /** The system calls this to perform work in the UI thread and delivers
          * the result from doInBackground() */
        protected void onPostExecute(Bitmap result) {
            mImageView.setImageBitmap(result);
        }
    }
    View Code

    主要是在另外一个线程工作的函数式doInBackground(),这个函数返回的值就是onPostExcute里面的参数

    具体看如下官方文档

    You should read the AsyncTask reference for a full understanding on how to use this class, but here is a quick overview of how it works:

  • 相关阅读:
    非常精辟的几句话
    关于免杀的实践
    分析PE
    分析 Nanocore
    CTO的窘境
    企业级容器云平台
    POJ 2274
    POJ 1703
    POJ 1182
    DNS协议以及报文格式总结
  • 原文地址:https://www.cnblogs.com/juncent/p/3262773.html
Copyright © 2011-2022 走看看