zoukankan      html  css  js  c++  java
  • async的用法

    package com.example.administrator.myapplication;
    
    import android.os.AsyncTask;
    import android.util.Log;
    import android.widget.TextView;
    
    import java.io.IOException;
    
    
    public class DownloadTask extends AsyncTask<Object,Integer,Boolean> {
        private TextView tv;
    
        @Override
        protected Boolean doInBackground(Object... params) {
            tv=(TextView) params[0];
            int percent=0;
            try{
                while (true){
                    percent++;
                    Thread.sleep(1000);
                    publishProgress(percent);
                    if(percent>=100){
                        break;
                    }
                }
            }catch (Exception e){
                return false;
            }
            return true;
        }
    
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
    
        private static final String TAG = "DownloadTask";
        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            tv.setText(values[0].toString());
            
            Log.d(TAG, "onProgressUpdate: "+values[0]);
        }
    
        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            Log.d(TAG, "onPostExecute: ");
        }
    }
  • 相关阅读:
    LeetCode
    LeetCode
    ELK系列(5)
    ELK系列(4)
    ELK系列(3)
    ELK系列(2)
    ELK系列(1)
    计算机网络常见面试题总结
    mosquitto启动时Address already in use 和 一般的 Address already in use
    size和STL中的size_type
  • 原文地址:https://www.cnblogs.com/norm/p/8215330.html
Copyright © 2011-2022 走看看