Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6643247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:01:44+00:00 2026-05-26T00:01:44+00:00

Anyone know why AsyncTask is force closing when I try to unzip a file

  • 0

Anyone know why AsyncTask is force closing when I try to unzip a file in the background, it works when not using AsyncTask so I’m not sure what I am doing wrong:

public class UnzipFile extends AsyncTask<Void, Integer, String> {                                                        
String zipFile = Environment.getExternalStorageDirectory() + "/download/" + mixtapefilename; 
String unzipLocation = Environment.getExternalStorageDirectory() + "/download/";

    @Override
    protected void onPreExecute() {         
        Toast toast = Toast.makeText(getApplicationContext(), "Unzipping...", Toast.LENGTH_SHORT);
        toast.show();

       /* Intent intent = new Intent();
        final PendingIntent pendingIntent = PendingIntent.getActivity(Download.this, 0, intent, 0);

        // configure the notification
        notification = new Notification(R.drawable.zipicon, "Unzipping...", System
                .currentTimeMillis());
        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
        notification.setLatestEventInfo(getApplicationContext(), "Please Wait", "Unzipping...", pendingIntent);
        notificationManager2.notify(1, notification);*/

    }

    @Override
    protected String doInBackground(Void... params) {                         
        Decompress d = new Decompress(zipFile, unzipLocation); 
        d.unzip();               

        return "success";}                              

    @Override
    protected void onPostExecute(String result) {
        Toast toast = Toast.makeText(getApplicationContext(), "Download Complete", Toast.LENGTH_SHORT);
        toast.show();
        File oldzip = new File(zipFile);
        boolean deleted = oldzip.delete();
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
        /*notificationManager2.cancel(1);*/                             
    }
}       

and then here is my unzip portion that I am trying to run in the background

public class Decompress { 
      byte[] buffer = new byte[1024];
      int length;
      private String _zipFile; 
      private String _location; 

      public Decompress(String zipFile, String location) { 
        _zipFile = zipFile; 
        _location = location; 
       File a = new File(_location + foldername); 
        if(!a.isDirectory()){
            a.mkdirs();
        }                        

        _dirChecker(""); 
      } 

      public void unzip() { 

        try  { 
          FileInputStream fin = new FileInputStream(_zipFile); 
          ZipInputStream zin = new ZipInputStream(fin); 
          ZipEntry ze = null; 
          while ((ze = zin.getNextEntry()) != null) { 


            if(ze.isDirectory()) { 
              _dirChecker(ze.getName()); 
            } else { 
              FileOutputStream fout = new FileOutputStream(_location + ze.getName()); 
              while ((length = zin.read(buffer))>0) {
                  fout.write(buffer, 0, length);
                  }

              zin.closeEntry(); 
              fout.close(); 
            } 

          } 
          zin.close(); 
          Toast toast = Toast.makeText(getApplicationContext(),"Download Complete", Toast.LENGTH_LONG);
          toast.show();
        } catch(Exception e) { 
            ProgressDialog dialog;
         dialog = new ProgressDialog(Download.this);                
         dialog.setMessage(e.toString());
         dialog.show(); 
        } 

      } 

      private void _dirChecker(String dir) { 
        File f = new File(_location + dir); 


        if(!f.isDirectory()) { 
          f.mkdirs(); 
        } 
      } 
    } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:01:44+00:00Added an answer on May 26, 2026 at 12:01 am

    Since you are using AsynTask you can not communicate with main UI thread (i.e. display toast messages) inside doInBackground().

    The only way to communicate with the main UI thread during AsynTask is by using onPreExcute() or onPostExcute()

    So just remove this line:

    Toast toast = Toast.makeText(getApplicationContext(),"Download Complete", Toast.LENGTH_LONG);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone see what Im doing wrong here? I know it is a lot
Anyone know what would make vs2010 not deploy .json files when doing a publish?
I am using an AsyncTask to handle complex background operations (compiling a log file
Anyone know how to do this without using a third party program? If there
Anyone know a good Regex expression to drop in the ValidationExpression to be sure
Anyone know how to get rid of those line borders in Eclipse (using Aptana
Anyone know why the following is not working? C#: public partial class Default :
Anyone know a good solution? So far I have not found a better way
Does anyone know how to easily arrange multiple calls to an AsyncTask execution in
Anyone know why rails, places attachments at the top of the email and not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.