小编Tom*_*ble的帖子

如何调试AsyncTask的doInBackground代码

我设置了断点,但它们似乎被忽略(或从未见过).

我的代码如下.我正在尝试将sql db备份到SD卡.

当我在eclipse中运行它(不是调试模式)时,我从onPreExecute获取消息,然后紧接着来自onPostExecute的消息.

我在ExportDatabaseFileTask的几乎每一行都设置了BreakPoints.

当我在eclipse中运行它(在调试模式下)时,我停在onPreExecute的断点处,然后当我走得更远时,调试器进入的非常接近的行是:

mDbHelper.open();

然后我逐步完成剩下的正常代码,并且AVD显示来自onPreExecute的消息,它显然会保持不变.

我没有看到任何突破的线路:

doInBackground onPostExecute copyFile

因此,我必须恭敬地不同意我没有明确指出或没有被执行的评论.所以,我将重新提出我的问题:如何调试(STEP THROUGH)AsyncTask的doInBackground代码?

        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 …
Run Code Online (Sandbox Code Playgroud)

eclipse android android-asynctask

17
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

android-asynctask ×1

eclipse ×1