I need to insert bulk of data to database in my android application. I have a dialog box containing a listview which have rows name, date, frequency where frequency value would be anything like "Daily", "Monthly", "Quarterly", "Yearly". Here after adding rows to the listview I need to click the done button to save these data's to the database. I need to store each row based on its frequency value. That is, if the frequency value is "Daily" I need to store 1095 (i.e., 3*365-->daily records for 3 year) record to the database for that name, similarly for each frequency value ("Monthly"--> 3*12, "Quarterly"--> 3*4,...) so it cause a bulk insertion of rows to database and which results long time to executes so the user may feel bad and he can't do any other operations in the application without completing this.I am using ORMLite for adding data to database.I have done this as below.
for (int i = 0; i < listAdapter.getCount(); i++) {
Account rowAcct = new Account();
rowAcct = listAdapter.getItem(i);
if (rowAcct.getFreq().equals("Daily")) {
for (int y = 0; y < 1095; y++) {
Account nwEvt = new Account();
dueDt = saveController.getNextDay(dueDt);
nwEvt.setDueDate(dueDt);
evtId = saveController.createAcc(nwEvt);
}
} else if (rowAcct.getFreq().equals("Monthly")) {
for (int y = 0; y < 35; y++) {
Account nwEvt = new Account();
Date dueDt = saveController.getNextMonth(dueDt);
nwEvt.setDueDate(dueDt);
saveController.createAcc(nwEvt);
}
} else if (rowAcct.getFreq().equals("Quarterly")) {
for (int y = 0; y < 11; y++) {
Account nwEvt = new Account();
dueDt = saveController.getQuarterMonth(dueDt);
nwEvt.setDueDate(dueDt);
evtId = saveController.createAcc(nwEvt);
}
} else if (rowAcct.getFreq().equals("Half-Yearly")) {
for (int y = 0; y < 5; y++) {
Account nwEvt = new Account();
Date dueDt = saveController.getHalfYear(dueDt);
nwEvt.setDueDate(dueDt);
saveController.createAcc(nwEvt);
}
} else if (rowAcct.getFreq().equals("Yearly")) {
for (int y = 0; y < 2; y++) {
Account nwEvt = new Account();
Date dueDt = saveController.getNextYear(dueDt);
nwEvt.setDueDate(dueDt);
saveController.createAcc(nwEvt);
}
}
}
dialog.dismiss();
How can I minimise this insertion time or making this insertion process in background and make the user free to do other things in the application? Please suggest me the best way to perform this by making the user free.