Android中AsyncTask的用法实例分享

2019-12-10 20:09:30刘景俊

                        baos.write(buf, 0, ch);  
                        count += ch;  
                        if (length > 0) {  
                            // 如果知道响应的长度,调用publishProgress()更新进度  
                            publishProgress((int) ((count / (float) length) * 100));  
                        }  
                        // 为了在模拟器中清楚地看到进度,让线程休眠100ms  
                        Thread.sleep(100);  
                    }  
                    s = new String(baos.toByteArray());            }  
                // 返回结果  
                return s;  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
            return null;  
        }  
        @Override  
        protected void onCancelled() {  
            super.onCancelled();  
        }  
        @Override