Nature of an Async Task

Consider the code in Listing 18–10, where a menu item is invoking two async tasks one after the other.

Listing 18–10. Invoking Two Long-Running Tasks

void respondToMenuItem() {     MyLongTask mlt = new MyLongTask(this.mReportTo,this.mContext,"Task1");     mlt.execute("String1","String2","String3");          MyLongTask mlt1 = new MyLongTask(this.mReportTo,this.mContext,"Task2");     mlt1.execute("String1","String2","String3"); }

Here we are executing two tasks on the main thread. You would expect both the tasks to get started close to each other. However, the preferred default behavior is to run them sequentially using a single thread drawn out of a pool of threads.

Here is what the SDK documentation tells us about this ...

Get Pro Android 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.