android - Disable use of AsyncTask, using custom AsyncTask -


i have following implementation of asynctask, allowing multiple asynctasks 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 in myasynctask.

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

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -