/**   
     * 将一个InputStream里面的数据写入到SD卡中   
     * @param path   
     * @param fileName   
     * @param input   
     * @return   
     */   
    public File write2SDFromInput(String path,String fileName,InputStream input){
        File file = null;   
        OutputStream output = null;   
        try {   
            createSDDir(path);   
            String str = path + fileName;
            file = createSDFile(path + fileName); 
            output = new FileOutputStream(file);   
            byte[] buffer = new byte[FILESIZE];   
            while((input.read(buffer)) != -1){   
                output.write(buffer);   
            }   
            output.flush();   
        }    
        catch (Exception e) {   
            e.printStackTrace();   
        }   
        finally{   
            try {   
                output.close();   
            } catch (IOException e) {   
                e.printStackTrace();   
            }   
        }   
        return file;   
    }
如何在下载代码中加阻塞,让他下载完再执行后面的程序。请各位帮忙看看

解决方案 »

  1.   

    阻塞?UI阻塞时间超过5s会有ANR,只能通过handler和thread配合实现,而且阻塞的期间也得有个提示或者什么窗口之类的
      

  2.   

    那怎么弄好呢,想C# 从com端口取数据的时候直接用cretefile函数 参数就带个 阻塞 。这个还没搞过不知道从哪下手了其实就想实现,调用下载文件函数,等到下载完后再从调用下载函数这往下执行
      

  3.   

    安装和下载放到同一个线程就行了,java这水平触发的
      

  4.   

    不行呀,我下载图片----->到显示图片就是在一个函数里写的,没用多线程,那这不就属于单线程了么
    代码如下:下载和显示都在一个单击时间里面//ListView单击事件
    list_view_presentation.setOnItemClickListener(new OnItemClickListener(){
    .
    .
    .
    .
    .
    .
    //下载函数downFile
    int result = downloader.downFile("http://172.16.0.78:8082/upload/download/"+presentationName+"/"+presentationName+"_1.jpg", "download/"+presentationName+"/", presentationName+"_1.jpg");

    //接下来就是现实图片的方法了
    sum =1;
    setHtml(imagePath+presentationName+"/"+presentationName+"_1.jpg");
    imageName = presentationName;
    webview.loadDataWithBaseURL("about:blank", html, "text/html", "utf-8",null);
    webview.setVisibility(View.VISIBLE);
    }}); }
      

  5.   

    参考:
    Android显示在线图片
      

  6.   

    加个死循环
    while(true){
    if("判断如果下载完"){
    break;
    }
    }
    下载完要运行的语句....