중단 점을 설정했지만 무시되거나 보지 못했습니다.어떻게 AsyncTask의 doInBackground 코드를 디버깅 할 수 있습니까?
내 코드는 다음과 같습니다. SQL 데이터베이스를 SD 카드에 백업하려고합니다.
이클립스에서 (디버그 모드가 아닌) 실행했을 때, 나는 onPreExecute로부터 메시지를 받았고 곧바로 onPostExecute의 메시지가 나왔다.
나는 ExportDatabaseFileTask의 거의 모든 줄에 BreakPoints를 설정했습니다.
내가 이클립스 (디버그 모드)를 실행하면, 내가 onPreExecute에서 중단 점에서 중지, 그리고 내가 더 단계로 다음, 바로 다음 라인은 디버거가 간다은 다음과 같습니다
mDbHelper.open() ;
정상 코드의 나머지 부분을 단계별로 실행하고 onPreExecute에서 메시지를 보여주는 AVD와 함께 남았습니다. 분명히 영원히 머무를 것입니다. 나는 정중하게 나는 그것이 breakpointed하지 않아도 주석에 동의해야하거나하지 CopyFile 수
그래서
doInBackground onPostExecute :
나는에 BREAKPOINTED 라인 중 하나를 볼 수 없습니다 실행되고있다. 그래서, 내 질문을 다시 드릴 게요 : 어떻게 당신이 디버깅 (단계) doInBackground 코드 AsyncTask합니까? 그들이 무시하는 경우
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<String, Void, Boolean> {
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();
}
}
}
}
시도 : –
@Tom Wruble -'Log.d()'지문을'doInBackground'에 추가 했습니까? 그들이 인쇄 되었습니까? – MByD
필자는이 두 줄 사이를 읽고 있지만, AsyncTask의 모든 코드를 단계적으로 수행 할 수는 없으며 디버깅하는 방법은 Log 문을 통해 수행하는 것으로 나타났습니다. 그게 사실이라면, 나는 그것을 처리 할 수있다. 하지만 처음에는 내가 Breakpoints를 설정하지 않았거나 codxe가 실행되지 않았다고 말했고 디버그를 통해 AysyncTask에서 코드를 단계별로 실행할 수 있음을 암시합니다. –