How to pass values to AsyncTask Android -
this first time using asynctask , little confused well, passing values.
i have 4 arraylist<string>
s, contain data should inserted database. want insertion done in background. there minimum of 50 rows inserted database , 1 row inserted @ time, taking passing values 4 arraylists have.
can guide me on how this?
now create subclass insertdata extends asynctask :::
private class insertdata extends asynctask<params, progress, result>{ @override protected result doinbackground(params... params) { // todo auto-generated method stub return null; } }
i have values in 4 arraylists, in need retrieve 1 entry each arraylist , pass 4 values database. how pass these 4 values asynctask , also, how repeat till there entries in arraylists.
here database method inserts 1 row database :::
public void insert_row(int count, string image_url, string name, string number) { // todo auto-generated method stub db.execsql("insert contacts values('"+ count +"', '"+ image_url +"', '"+ name +"', '"+ number +"')"); }
if can give me overview on how can implement this, great.
try following, and, anyway, create constructor insertdata
parameters need, store them in insertdata
class fields , use in doinbackground()
.
private class insertdata extends asynctask<arraylist, progress, result>{ @override protected result doinbackground(arraylist... params) { // todo auto-generated method stub arraylist list1 = params[0]; arraylist list2 = params[1]; ... return null; } }
call:
insertdata task = new insertdata(); task.execute(yourlist1, yourlist2, yourlist3...);
Comments
Post a Comment