Faster / fastest way to get new SMS when launching the app – Android
I have a SQLite database, which contains all the user's SMS, but when you start the application, if the user decides to use a different SMS application, I need to get all the SMS I may not have
I'm looking for the best way to synchronize my database with a basic Android content provider
At present, I insert or ignore each SMS, as shown below:
insert or ignore into sms (smsID, smsCONID, smsMSG, smsNUM, smsREAD, smsTIMESTAMP, smsTYPE, smsSHORTMSG) values (?,?,?,?,?,?,?,?);
I load my inbox and send messages as separate asynctasks in my splash screen activity, which takes about 10 seconds
My doinbackground:
@Override
protected Void doInBackground(Void... arg0) {
int thread_id = 0;
int _id = 0;
int read;
String number;
boolean first = true;
String msg;
long timestamp;
/**
* RECUPERATION DES MESSAGES RECUS
*/
// PREPARE CURSOR
cursorIn@R_903_2419@.moveToFirst();
while (cursorIn@R_903_2419@.moveToNext()) {
if(first){
cursorIn@R_903_2419@.moveToFirst();
first = false;
}
// RECUPERE THREAD_ID + ID_SMS + NUMERO DU CONTACT
thread_id = cursorIn@R_903_2419@.getInt(cursorIn@R_903_2419@.getColumnIndexOrThrow("thread_id"));
_id = cursorIn@R_903_2419@.getInt(cursorIn@R_903_2419@.getColumnIndexOrThrow("_id"));
number = cursorIn@R_903_2419@.getString(cursorIn@R_903_2419@.getColumnIndexOrThrow("address"));
msg = cursorIn@R_903_2419@.getString(cursorIn@R_903_2419@.getColumnIndexOrThrow("body"));
read = cursorIn@R_903_2419@.getInt(cursorIn@R_903_2419@.getColumnIndexOrThrow("read"));
timestamp = cursorIn@R_903_2419@.getLong(cursorIn@R_903_2419@.getColumnIndexOrThrow("date"));
// CREER LE SMS
dataManip.insert(_id, thread_id, msg, number, read, timestamp, "received",ContactsFactory.getMessageShort(msg));
i++;
publishProgress(i);
}
Log.d(TAG,"LoadActivity - In@R_903_2419@ Loaded");
return null;
}
Driving ideas?
resolvent:
How do I listen to the registering a contentobserver in a separate service to listen to changes from the Android SMS provider? I'm not sure if it will inform the observer about changes. But if so, your database will always be synchronized. But don't just rely on it, because the service may terminate at any time for various reasons
For actual synchronization, please ensure that the "_id" column in the table is primary key. Query the content providers sorted by "_id". Query your own table sorted by "_id" and read all IDs. Now traverse the two sorted lists, insert your missing items and delete the items missing content providers. You also want to delete messages deleted by other SMS applications, don't you? The insert or ignore statement does not delete missing rows for you