I am creating a test application whose purpose is to import a large amount of text messages into the sms inbox. I have a few thousand messages in two columns “address” and “body”. I can have them in a csv, sqlite, or string array format. I’m unsure how to approach this problem so as to make this while loop efficient and what way I might want to parse the data.
Please instruct as to the best approach to accomplish this.
For simplicity sake I’ve tried it as an array here but there are some syntax errors.What is the correct way to use an array to add values into the database?
Here is what I have so far:
private void importSms(final String[] addressvariable, final String[] bodyvariable) {
Thread queue = new Thread(new Runnable() {
public void run() {
while(true) { //will have to define this boolean
ContentValues values = new ContentValues{);
values.put("address", [addressvariable]);
values.put("body", [bodyvariable]);
getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
}
}
});
queue.start();
Long operation like this one should be done using an AsyncTask. This will make sure you don’t block the UI thread, and allow you to easily show a progress dialog while processing, keeping the user informed.
As for the format, I’d go with a database as it can be easily upgraded later on and modified to newer needs. Using a String array for this would be rather complicated, especially if your messages are formatted. CSV parsing isn’t natively supported, so I’d not pick it over a database.