Second AsyncTask not executing

后端 未结 5 449
暗喜
暗喜 2021-01-04 22:34

I have 2 AsyncTask, one which is creating a socket connections and anotherone that is transmitting objects using those sockets. my code is this:

try {
               


        
5条回答
  •  时光说笑
    2021-01-04 23:12

    I had wrote class for execute AsyncTask concurrently.

    Check it out:

    Android-AsyncTask-Executor

    It takes all work for running AsyncTask concurrently on any Android OS version, it is better that using:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        task.execute();
    }
    

    Because AsyncTask.THREAD_POOL_EXECUTOR available only on api >= 11

    With my class you just need to write:

    AsyncTaskExecutor.executeConcurrently(task, params);
    

    And that is all. No errors on Android 2.x, 3.x and 4.x

提交回复
热议问题