I am saving some data in a database using asynctask with a loop like this:
for(int i=0;i<5;i++){
new Loader().execute(i);
}
and in my asynctask class the doinbackground method is like this:
@Override
protected Void doInBackground(Integer... params) {
db.insert(params[0]);
return null;
}
its being executed but everytime its inserting the first value of i in the database? how to work it with corresponding this loop?
You can do something like:
and you call
new Loader().execute(1, 2, 3, 4, 5);You save memory by creating only one
AsyncTaskobject instance