I am developing a small application with lot of db operations in it. Basically its a tab activity, having 3 tabs in it. each tab will show data by parsing xml files. 3 tab activities are using same db object, so that am able to see only 2 tabs filled with data, where 3rd one always showing progress dialog which i created. following is my async task where am populating db.
protected void onPreExecute() {
super.onPreExecute();
sdbop = new SDBOperations(context);
hdbop = new HDBOperations(context);
pdbop = new PDBOperations(context);
sdbop.open();
hdbop.open();
pdbop.open();
}
@Override
protected Void doInBackground(UpdateXML... statuslist) {
for(UpdateXML status:statuslist){
if(status==UpdateXML.C){
checkStatusAndPopulateDB(status,null);
continue;
}
String url = getUpdateURL(status);
String xml = XMLParser.getXmlFromUrl(url);
if(xml!=null)
checkStatusAndPopulateDB(status,xml);
}
return null;
}
private void checkStatusAndPopulateDB(UpdateXML status, String result) {
switch (status) {
case S:
sdbop.open();
dropTable();
insertIntoSTable(result);
sdbop.close();
updateSList();
break;
case H:
hdbop.open();
dropHTable(hdbop);
insertIntoHTable(hdbop,result);
hdbop.close();
updateHList();
case P:
pdbop.open();
dropPTable(pdbop);
insertIntoPTable(pdbop, result);
pdbop.close();
updatePList();
break;
case C:
updateLView();
break;
default:
break;
}
so every thing is working ok. but db object is accessable by 3 tasks continuously. so that one of my tab is always in waiting stage and view is also in progress. So, if there is one task is accessing db, others should be in waiting. how to handle this situation?