Open/close database ASAP

This commit is contained in:
Mathieu Maret 2011-10-30 01:17:17 +02:00
parent 1119047891
commit 33ece37bba

View File

@ -218,7 +218,7 @@ public class MultiSmsSender extends Activity {
} }
public void sendMessage(Handler handler) { public void sendMessage(Handler handler) {
DeliveryDbAdapter mDbHelper = new DeliveryDbAdapter(this); DeliveryDbAdapter mDbHelper = new DeliveryDbAdapter(this);
mDbHelper.open();
SmsManager manager = SmsManager.getDefault(); SmsManager manager = SmsManager.getDefault();
String message = mEditor.getText().toString(); String message = mEditor.getText().toString();
HashMap<String, Long> deliveryIdMap = new HashMap<String, Long>(); HashMap<String, Long> deliveryIdMap = new HashMap<String, Long>();
@ -241,9 +241,11 @@ public class MultiSmsSender extends Activity {
if (haveDeliveryReports) { if (haveDeliveryReports) {
mDbHelper.open();
deliveryId = mDbHelper.createDelivery(message.substring(0, Math.min(30, message deliveryId = mDbHelper.createDelivery(message.substring(0, Math.min(30, message
.length())).replace('\n', ' '), DateFormat.getDateInstance() .length())).replace('\n', ' '), DateFormat.getDateInstance()
.format(new Date())); .format(new Date()));
mDbHelper.close();
} }
@ -256,14 +258,16 @@ public class MultiSmsSender extends Activity {
&& !phoneNumberConform.contains(newN)) { && !phoneNumberConform.contains(newN)) {
phoneNumberConform.add(newN); phoneNumberConform.add(newN);
if(haveDeliveryReports) { if(haveDeliveryReports) {
mDbHelper.open();
long entryId = mDbHelper.createEntry(mDbHelper.nameFromNumber(newN), newN, deliveryId); long entryId = mDbHelper.createEntry(mDbHelper.nameFromNumber(newN), newN, deliveryId);
deliveryIdMap.put(newN,entryId); deliveryIdMap.put(newN,entryId);
}
}
}
mDbHelper.close(); mDbHelper.close();
}
}
}
numbers = new String[size]; numbers = new String[size];