How should I decompress a large data file in AsyncTask.doInBackground?
<p>I have a large data file, which is zipped, and approximately 20MB. When it's unzipped, it's up to about 50MB. The following source code works fine. I found the original on the web somewhere else and modified it a bit. And this method is called within the AsyncTask.doInBackground.</p>

<p>So, what I want to know is, how can I save the on going status(? sorry, I don't know the proper English word) and resume the procedure later? I mean, this method takes a bit long time (about a minute on an emulator), and I know there is no way since the data is kind of huge. So, if a main activity of this method gets killed, I want to save the current status of decompressing the file, and when the activity gets active, I want to resume decompressing from the last point. Hope my explanation clears my intent.</p>

<p>I was thinking using a service, but I also want to interact with UI, such as showing a progress or whatever. I can't find good information to do that in the service when I roughly scan the reference, but is there a way to do that in the service? And do you think I should use it?</p>

<p>Anyway, my main point is how to resume decompressing a file.</p>

<pre><code>private final static int CHUNK_SIZE = 32 * 1024;
byte[] _fileIOBuffer = new byte[CHUNK_SIZE];

public void unzipFile(DBFileDownloader downloader, File zipFile, String directory) 
    throws IOException
{ 
    ZipInputStream in = null; 
    FileOutputStream os = null; 
    try 
    {
        in = new ZipInputStream (new FileInputStream(zipFile)); 
        ZipEntry entry = null; 
        while ((entry = in.getNextEntry ())!= null) 
        { 
            String entryName = entry.getName();                 
            if (entry.isDirectory ()) { 
                File file = new File (directory, entryName); 
                file.mkdirs(); 
            } 
            else { 
                File file = new File(directory, entryName);
                if (file.exists()){
                    file.delete();  // I don't know how to append, so delete it always
                }
                os = new FileOutputStream (file); 

                int bytesRead = 0; 
                while ((bytesRead = in.read (_fileIOBuffer))!= -1) {
                    os.write(_fileIOBuffer, 0, bytesRead);
                    // progress procedure
                }
                os.close();
            }
        }
    }
    catch (FileNotFoundException e) {        
        Log.v("unzip", e.getMessage());
    } 
    catch (IOException e) {
        Log.v("unzip", e.getMessage());
    } 
    finally{
        if (in != null ){
            in.close();
        }
        if (os != null ){
            os.close();
        }
    }
}       
</code></pre>

<p>Thanks in advance,
yokyo</p>
