Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        4年前关闭。
                    
                
        

我已经在我的Android项目中添加了zip4j库。这是非常容易使用。

ZipFile zipFile = new ZipFile(downloadedFilePath);
zipFile.extractAll(context.getFilesDir().getPath());


但是我担心一个功能。他们使用while-loop而不是订阅来获得解压缩的进度,如下所示:

while (pm.getState() == ProgressMonitor.STATE_BUSY) {
    // my progress handler is here
}


如果我需要知道解压缩已完成,则应按以下方式使用它:

while (pm.getState() == ProgressMonitor.STATE_BUSY) {
    // the loop runs until progress monitor changes its status
}
if (pm.getResult() == ProgressMonitor.RESULT_SUCCESS) {
    // my code to handle completion
}


对我来说,它看起来像是反模式和不良的编码。我应该在我的项目中使用,还是切换到其他zip库?

最佳答案

while循环将使用CPU资源并使其繁忙。我建议使用Thread并使其休眠一会儿,然后再次检查pm.getState()并更新进度条

07-24 09:45
查看更多