android - Disable use of AsyncTask, using custom AsyncTask -
i have following implementation of asynctask
, allowing multiple asynctask
s run concurrently:
public abstract class myasynctask<params, progress, result> extends asynctask<params, progress, result> { public asynctask<params, progress, result> executecompat(params... params) { if (build.version.sdk_int >= build.version_codes.honeycomb) { return executeonexecutor(thread_pool_executor, params); } else { return execute(params); } } }
now avoid confusion , accidental use of normal asynctask
, block access code to:
- the
asynctask
class,myasynctask
should used. - the
execute()
function inmyasynctask
.
is possible this?
my idea of doing bit different. instead of extending asynctask
class, can create method takes parameter asynctask
want use. here example:
public void executeasynctask(asynctask asynctask) { if (build.version.sdk_int >= build.version_codes.honeycomb) { asynctask.executeonexecutor(thread_pool_executor, params); } else { asynctask.execute(params); } }
with need instantiate asynctask want use without worrying problems mentioned since extending android's
asynctask
class having overriden execute
method way want. lets have defined asynctask
named customasynctask
, execute call executeasynctask(new customasynctask(your_params));
can define above method in static
class (making method static
) easier access.
hope helps:)
Comments
Post a Comment