I was wondering whether there is a way to check when the database was last updated?
I’m currently checking to see if the database exists at the moment – if so, dont update, but i was wondering to see if, for example it has been 7 days since the last update – then update.
private boolean checkDataBase()
{
SQLiteDatabase checkDB = null;
try
{
checkDB = SQLiteDatabase.openDatabase(DB_FULL_PATH, null,
SQLiteDatabase.OPEN_READONLY);
checkDB.close();
}
catch (SQLiteException e)
{
// database doesn't exist yet.
}
return checkDB != null ? true : false;
}
Any suggestions or tutorials would be appreciated.
Regards
When you update the database you could save a
longvalue toSharedPreferencesthat represents the time of update usingSystem.currentTimeMillis()for example.Next time you want to check if an update is required simply retrieve the last update time and compare with
System.currentTimeMillis()to see if the difference is greater than 7 days.