parameters - Android AsyncTask as method argument -


i'm working on app uses lot of asynctasks. when started participate @ coding of app targetsdkversion set 10 hadn't problems asynctasks because executed on parallel background threads. since have set targtsdkversion 17 we've got problems tasks because executed on single background thread. solve problem i've found following code use parallel tasks:

if (build.version.sdk_int >= build.version_codes.honeycomb) {     mytask.executeonexecutor(asynctask.thread_pool_executor); } else {     mytask.execute(); } 

now, because have several tasks needing these lines of code, write method in our own utils class executes tasks in manner... can't achieve this, because can't pass different tasks method argument due 'param | progress | result' stuff differs 1 task another. there way achieve our goal? ideas?

since asynctask parameterized class, need use generics. this:

@suppresslint("newapi") static <p, t extends asynctask<p, ?, ?>> void execute(t task, p... params) {   if (build.version.sdk_int >= build.version_codes.honeycomb) {     task.executeonexecutor(asynctask.thread_pool_executor, params);   } else {    task.execute(params);   } } 

use this:

myasynctask task = new myasynctask(); utils.execute(task); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -