On Friday, April 20, 2012 3:16:35 PM UTC-4, Nathan wrote:
>
> Still adjusting to the changes in Android 4.0 regarding AsyncTask.
>
> If I understand right, the default behavior of execute is changing to one
> single thread pool with only one thread? With the reason cited that
> programmers are not capable of handling a bigger threadpool (I'm
> paraphrasing).
>
>
I'm also trying to figuring out why setDefaultExecutor is hide but public?
/** @hide */
public static void setDefaultExecutor(Executor exec) {
sDefaultExecutor = exec;
}
Is this because it is subject to change and non-framework clients (i.e.
third party dev) should be use this? For my app I wanted to globally change
the Executor to ThreadPool, but that doesn't seem possible.
So what I'm currently doing is subclass the AsyncTask like so:
public abstract class ThreadPoolAsyncTask<Params, Progress, Result>
extendsAsyncTask<Params, Progress, Result> {
/*
* This is a helper method to allow ICS AsyncTask to run in a thread pool,
* without break API compatability with pre-ICS devices.
* If you don't want a threadpool use the default AsyncTask since that is
the
* default for ICS. If you don't want a threadpool for pre-ICS (API level
< 13)
* then you need to wrote your own AsyncTask. Use the AsyncTask.java as a
good starting point.
*/
public void executeOnThreadPool(Params...params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
this.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
} else {
this.execute(params);
}
}
}
I'm just wondering is this is a good solution? This way I can use
ThreadPoolAsyncTask for task that can run in parallel and don't have any
implicit dependence on other tasks. And use AsyncTask directly if i want
them to run in serial.
Thanks,
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en