this is my code and i am trying to retrieve the date of the sms that i have stored in my database, and pass it in an object to compare if the date has aged after 30 days and have a toast message that it expires.Thanks in advance for help
public class DataAging extends Activity implements Runnable {
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
private final long ONE_DAY = 24 * 60 * 60 * 1000;
public void onCreate(Bundle savedInstanceState) {
run();
}
public String date;
public long dbDate;
@Override
public void run() {
ArrayList<Message> smsInbox = new ArrayList<Message>();
String query_fetchSMS = "select * from " + Constants.table_sms + ";";
smsDB smsD = new smsDB(this);
SQLiteDatabase dbw = smsD.getWritableDatabase();
Cursor cursor = dbw.rawQuery(query_fetchSMS, null);
if (cursor != null) {
cursor.moveToLast();
if (cursor.getCount() > 0) {
do {
String time;
time = (cursor.getString(cursor
.getColumnIndex(Constants.columns_sms_date)));
SimpleDateFormat dateFormat = new SimpleDateFormat("hmmaa");
try {
Date date = dateFormat.parse(time);
Date now = new Date();
long diff = now.getTime() - date.getTime();
long days = diff / ONE_DAY;
if(days > 1) { // More than 30 days?
// Expired !!!
Toast.makeText(context,"EXPIRED NA", Toast.LENGTH_SHORT).show();
}
} catch (ParseException e) {
}
} while (cursor.moveToPrevious());
}
}
dbw.close();
smsD.close();
}
}