title: android - How to check if a background thread is successful or not?
body: <p>I'm trying to extract RAR files with junRAR. But as I read from this question: <a href="https://stackoverflow.com/questions/14109455/outofmemoryerror-when-i-decompress-rar-file-on-android">OutOfMemoryError when I decompress RAR file on Android</a>, junRAR is not optimized yet for Android. So, what I want to do is to check if the extraction is successful or not, then give an error message if it fails.(because my app crashes if it the extraction is not successful). Can somebody tell me how can I do that checking? My thread is being done here:</p>
  
  <pre><code>public class MyTask extends AsyncTask&lt;Void, Void, Void&gt; {
  
    private ProgressDialog progress;
    public MyTask(ProgressDialog progress) {
        this.progress = progress;   
    }
  
    public void onPreExecute() {
      progress.show();
    }    
  @Override
  protected Void doInBackground(Void... params) {
      if(taskType==1){
           extractArchive(rarFile, destinationFolder);            
      }
  return null;
  }
  
  public void onPostExecute(Void unused) {
      progress.dismiss();
      if(taskType==1){
          refreshFileList();
          Toast.makeText(MainActivity.this, "Extracted to " + targetPath, Toast.LENGTH_LONG).show();
      }
  } 
  </code></pre>
  
  <p>Here's my Logcat error:</p>
  
  <pre>
  
  03-02 16:59:40.777: E/AndroidRuntime(28573): FATAL EXCEPTION: AsyncTask #1
  03-02 16:59:40.777: E/AndroidRuntime(28573): java.lang.RuntimeException: An error occured while executing doInBackground()
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at android.os.AsyncTask$3.done(AsyncTask.java:278)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at java.lang.Thread.run(Thread.java:856)
  03-02 16:59:40.777: E/AndroidRuntime(28573): Caused by: java.lang.OutOfMemoryError
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.github.junrar.unpack.ppm.SubAllocator.startSubAllocator(SubAllocator.java:146)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.github.junrar.unpack.ppm.ModelPPM.decodeInit(ModelPPM.java:216)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.github.junrar.unpack.Unpack.readTables(Unpack.java:656)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.github.junrar.unpack.Unpack.unpack29(Unpack.java:165)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.github.junrar.unpack.Unpack.doUnpack(Unpack.java:120)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.github.junrar.Archive.doExtractFile(Archive.java:501)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.github.junrar.Archive.extractFile(Archive.java:443)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.jearom.thesisfmanager.MainActivity.extractArchive(MainActivity.java:2270)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.jearom.thesisfmanager.MainActivity$MyTask.doInBackground(MainActivity.java:1962)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at com.jearom.thesisfmanager.MainActivity$MyTask.doInBackground(MainActivity.java:1)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  03-02 16:59:40.777: E/AndroidRuntime(28573):    ... 5 more
  03-02 16:59:41.437: E/WindowManager(28573): Activity com.jearom.thesisfmanager.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41d3a0c0 that was originally added here
  03-02 16:59:41.437: E/WindowManager(28573): android.view.WindowLeaked: Activity com.jearom.thesisfmanager.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41d3a0c0 that was originally added here
  03-02 16:59:41.437: E/WindowManager(28573):     at android.view.ViewRootImpl.(ViewRootImpl.java:344)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.view.Window$LocalWindowManager.addView(Window.java:537)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.app.Dialog.show(Dialog.java:278)
  03-02 16:59:41.437: E/WindowManager(28573):     at com.jearom.thesisfmanager.MainActivity$MyTask.onPreExecute(MainActivity.java:1867)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.os.AsyncTask.execute(AsyncTask.java:511)
  03-02 16:59:41.437: E/WindowManager(28573):     at com.jearom.thesisfmanager.MainActivity$6.onClick(MainActivity.java:752)
  03-02 16:59:41.437: E/WindowManager(28573):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.os.Handler.dispatchMessage(Handler.java:99)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.os.Looper.loop(Looper.java:137)
  03-02 16:59:41.437: E/WindowManager(28573):     at android.app.ActivityThread.main(ActivityThread.java:4456)
  03-02 16:59:41.437: E/WindowManager(28573):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-02 16:59:41.437: E/WindowManager(28573):     at java.lang.reflect.Method.invoke(Method.java:511)
  03-02 16:59:41.437: E/WindowManager(28573):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
  03-02 16:59:41.437: E/WindowManager(28573):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
  03-02 16:59:41.437: E/WindowManager(28573):     at dalvik.system.NativeStart.main(Native Method)
  
  </pre>