I want to run some code on the first startup of my application, it is to sync the past week’s SMS messages to my web application. I’m unsure of how to filter out anything over a week, but this is my code to get all sms messages:
Uri allMessage = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(allMessage, null, null, null, null);
while (c.moveToNext()) {
String row = c.getString(1);
//upload the recent 1 week sms messages to the server's database
}
I want to run this code only once, so right when it is opened for the first time.
Use
SharedPreferences. For example: