Android AsyncTask的doInBackground未启动

时间:2016-05-25 13:57:26

标签: android multithreading asynchronous android-asynctask

我的一个班级里面有一个AsyncTask。我正在执行AsyncTask,如:

  

mAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

当我调试我的app时,mAsyncTask的onPreExecute()函数被正确调用,但是没有调用doInBackground函数。 导致问题的原因是什么?

PlanRouteAsync代码: -

private class PlanRouteAsync extends AsyncTask<Void, Integer, Void>{

    @Override
    protected void onPreExecute(){
        super.onPreExecute();
        mIsRunning = true;
    }
    @Override
    protected Void doInBackground(Void... params){
        ...
        return null;
    }
    @Override
    protected void onProgressUpdate(Integer... values){
        super.onProgressUpdate(values);
        ...
    }
    @Override
    protected void onCancelled(){
        super.onCancelled();
        ...
    }
    @Override
    protected void onCancelled(Void aVoid){
        super.onCancelled(aVoid);
        ....
    }
    @Override
    protected void onPostExecute(Void aVoid){
        super.onPostExecute(aVoid);
        ....
    }
}

这是一个公司应用程序,几个AsyncTask在后台运行,但我已经读过,executeOnExecutor函数应该执行asycnTask并行。

我也读了这些帖子,但是他们没有帮助:

Android SDK AsyncTask doInBackground not running (subclass)

Android AsyncTask not working

编辑:

我的build.gradle文件:

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 23
    }
}

dependencies {
    compile project(':mPChartLib')
    compile project(':sVGSupport')
    compile 'com.google.android.gms:play-services:9.0.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:1.0.4'
}

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,我在后台有另一个Asynctask,它们也像mAsyncTask2.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);一样执行。由于特殊原因,这个AsyncTask从未完成它的doInBackground,这导致了这个问题。

所以我用一个新的Thread替换了另一个AsyncTask,它现在正在工作。 谢谢你的建议!

相关问题