ASyncTasks blocking others

后端 未结 3 1251
梦谈多话
梦谈多话 2021-01-31 16:37

I\'ve 2 ASyncTasks, one retrieves a value from an httpPost and the other update some elements of the UI (including an listview). The problem is that since both ASyncTasks share

3条回答
  •  滥情空心
    2021-01-31 17:06

    This is how I handle this in my code:

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

    And replace MyAsyncTask with yours Task1 and Task2 respectively. Basically change in AsyncTask appeared in Honeycomb (see Android SDK docs here in "Order of execution" section), so before that, you launch it as usual, for HC and up, use executeOnExecutor() if you do not like new behaviour (noone does, I think)

提交回复
热议问题