title: How can I debug doInBackground code of an AsyncTask
body: <p>I have breakpoints set, but they seem to be ignore (or never seen).</p>
  
  <p>My code is below. I'm trying to backup a sql db to an SD card. </p>
  
  <p>When I RUN it (not Debug mode) in eclipse, I get the message from the onPreExecute and followed shortly by the message from the onPostExecute. </p>
  
  <p>I have BreakPoints set in almost every line of the ExportDatabaseFileTask.</p>
  
  <p>When I RUN it (in Debug mode) in eclipse, I stop at the breakpoints in onPreExecute, and then as I step further, THE VERY NEXT LINE the Debugger goes to is:</p>
  
  <p>mDbHelper.open();</p>
  
  <p>I then step through the rest of the normal code and am left wth the AVD showing the message from the onPreExecute, wher it will apparently STAY FOREVER.</p>
  
  <p>I do NOT see any of the lines BREAKPOINTED in:</p>
  
  <p>doInBackground
  onPostExecute
  copyFile</p>
  
  <p>So, I have to respectfully disagree with the comment that I don't have it breakpointed or it is not being executed. So, I'll reask my question: How do you debug (STEP THROUGH) doInBackground code of an AsyncTask?</p>
  
  <pre><code>        case BACKUP_ID:
              if (ScoreAGame.this.isExternalStorageAvail()) {
                  mDbHelper.close();
                  new ExportDatabaseFileTask().execute();
                  mDbHelper.open();
              } else {
                  Toast.makeText(ScoreAGame.this, "External storage is not available, unable to export data.",
                             Toast.LENGTH_SHORT).show();
              }
              return true;
          case RESTORE_ID:
              selectCourse();
              return true;
      }
  
      return super.onMenuItemSelected(featureId, item);
  }
  
  private boolean isExternalStorageAvail() {
      return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
  }
  
  private class ExportDatabaseFileTask extends AsyncTask&lt;String, Void, Boolean&gt; {
      private final ProgressDialog dialog = new ProgressDialog(ScoreAGame.this);
  
      // can use UI thread here
      protected void onPreExecute() {
          this.dialog.setMessage("Exporting database...");
          this.dialog.show();
      }
  
      // automatically done on worker thread (separate from UI thread)
      protected Boolean doInBackground(final String... args) {
  
          File dbFile =
              new File(Environment.getDataDirectory() + "/data/com.discgolf/databases/discgolfdb.db");
  
          File exportDir = new File(Environment.getExternalStorageDirectory(), "discgolfbackup");
          if (!exportDir.exists()) {
              exportDir.mkdirs();
          }
          File file = new File(exportDir, dbFile.getName());
  
          try {
              file.createNewFile();
              this.copyFile(dbFile, file);
              return true;
          }
          catch (IOException e) {
              Log.e(TAG, e.getMessage(), e);
              return false;
          }
      }
  
      // can use UI thread here
      protected void onPostExecute(final Boolean success) {
          if (this.dialog.isShowing()) {
              this.dialog.dismiss();
          }
          if (success) {
              Toast.makeText(ScoreAGame.this, "Export successful!", Toast.LENGTH_SHORT).show();
          } else {
              Toast.makeText(ScoreAGame.this, "Export failed", Toast.LENGTH_SHORT).show();
          }
      }
  
      void copyFile(File src, File dst) throws IOException {
          FileChannel inChannel = new FileInputStream(src).getChannel();
          FileChannel outChannel = new FileOutputStream(dst).getChannel();
          try {
              inChannel.transferTo(0, inChannel.size(), outChannel);
          }
          finally {
              if (inChannel != null) {
                  inChannel.close();
              }
              if (outChannel != null) {
                  outChannel.close();
              }
          }
      }
  </code></pre>
  
  <p>}</p>