2

I have an AsyncTask inside one of my class. I am executing the AsyncTask like:

mAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

When I debug my app the mAsyncTask's onPreExecute() function is called correctly, but the doInBackground function is not called. What can cause the problem?

PlanRouteAsync Code:-

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);
        ....
    }
}

This is a company app, several AsyncTask is running in the background, but i have read, that the executeOnExecutor function should execute the asycnTask parallel.

I have read these posts also, but they didn't help:

Android SDK AsyncTask doInBackground not running (subclass)

Android AsyncTask not working

EDIT:

My build.gradle file:

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'
}
Community
  • 1
  • 1
bendaf
  • 2,981
  • 5
  • 27
  • 62
  • What's your `targetSdkVersion` ? – Prerak Sola May 25 '16 at 14:04
  • 2
    Not a direct solution to your problem, but I'd suggest staying away from AsyncTask in general, due both to it's lack of integration with the Activity Lifecycle and it's varying behavior across sdk versions. There are several other, better solutions, including my favorite, RxJava – GreyBeardedGeek May 25 '16 at 14:36
  • Thanks, I will take a look, but I don't really want to rewrite the full code :/. What do you think about ThreadPools? – bendaf May 25 '16 at 15:05
  • Your code snippet doesn't hold any information. What's inside of your `onPreExecute()` and `doInBackground()`? – Maxim G May 25 '16 at 15:07
  • I have added my onPreExecute() function, doInBackground() is irrelevant, because it's not running at all. – bendaf May 25 '16 at 17:34

1 Answers1

0

I solved the problem, I had an other Asynctask in the background which were executed like mAsyncTask2.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); also. This AsyncTask has never finished it's doInBackground for special reasons and this caused the problem.

So I replaced the other AsyncTask with a new Thread and it's working now. Thank you for your suggestions!

bendaf
  • 2,981
  • 5
  • 27
  • 62