I have a database in my application that is used as a ContentProvider.
It holds settings values for the application, and when I install the application I want it to add a hardcoded set of values just once.
This is how I am trying to do it at the minute.
if(settings.size()<= 0){
Settings s = new Settings("voipusernameTa", "xxxxxxxxx", "xxxxx",
"displayNameTa", "sip.networks.com", "sip.networks.com", "siprealmTa", 120);
addNewSettings(s);
}
And this is the addNewSettings method:
private void addNewSettings(Settings _settings) {
ContentResolver cr = getContentResolver();
String w = CiceroSettings._ID + " = " + _settings.get_Id();
Log.d("ADDNEW SETTINGS", "new setting id =" + _settings.get_Id());
Cursor c = cr.query(CiceroSettings.CONTENT_URI, null, w, null, null);
Log.d("CURSOR", "cursor created");
int dbCount = c.getCount();
c.close();
if (dbCount == 0){
ContentValues values = new ContentValues();
values.put(Settings._ID, _settings.get_Id());
values.put(Settings.VOIPUSERNAME, _settings.getVoipUserName());
values.put(Settings.VOIPAUTHID, _settings.getVoipAuthId());
values.put(Settings.PASSWORD, _settings.getPassword());
values.put(Settings.VOIPDISPLAYNAME, _settings.getVoipDisplayName());
values.put(Settings.SIPPROXYSERVER, _settings.getSipProxyServer());
values.put(Settings.SIPREGISTRAR, _settings.getSipRegistrar());
values.put(Settings.SIPREALM, _settings.getSipRealm());
values.put(Settings.EXPIRESTIME, Integer.toString(_settings.getExpiresTime()));
Log.d("CURSOR", "Values assigned");
cr.insert(CiceroSettings.CONTENT_URI, values);
Log.d("CURSOR", "Values inserted");
}
}
}
This works however each time the app starts it adds a new settings object and I only want it to app ONE object at the install of the application and thats it no more.
Has anyone a better solution for this? Or a reason why my code is flawed?