0

I get data asynchrounsly and this data gets plotted, got the logic worked out and now of course I need to run this smootthly so I use an AsyncTask when I get more data it is digested to a bitmap and plotted accordingly of course running on a loop without the AsyncTask works but on slower/older devices it is slugish, with the ASyncTask it seems like there is some sort of overrun as the bitmap/ImageView flickers

The items come in 5 different flavours so I set my parms properly when I make a new instance of the Asynctask and call execute to run a new instance of it

Now if a particular task for a specific flavour is running already how to check that??? so that I skip it until it finish processing the data for that type??? I needed to pass different data types so I used a list of Objects and that works

I know KISS is to make 5 different instances of the AsyncTask and check the taskInstance_n.getStatus() != AsyncTask.Status.RUNNING but I thought there may be a cleaner/cooler generic way to do it ????

    ArrayList<Object>parms = new ArrayList<Object>
    ...
    do
    {
      ..grab the data ...
      switch(id)
      {
        case 0:
                 parms.clear();
                 parms.add(arg1);
                 parms.add((type1)arg2)
                 parms.add((type2)arg3)
                 if( ! task is running with arg1)  ---->how do I do this
                    new myAsyncTask().execute(parms,null,null);

              break;
        case 1:
        ... other 4 choices simar way to call it
      }  // end of switch

      ...

  }while(i_get_data)
4

1 回答 1

0

与普遍的看法相反,AsyncTasks 不是并行运行的,它们形成一个队列并相互等待(HoneyComb 除外,但无论如何你都不应该以 API9-10 为目标)。所以你不应该担心两个 AsyncTasks 处理相同类型的数据,当你得到新的东西,准备好参数并开火时,它会耐心地等待,直到所有以前的 AsyncTasks 都完成。

于 2013-03-25T00:42:02.027 回答