私はAndroid SMSアプリを書いています。「content://sms/inbox」を使用して既存の SMS を読んでいます (文書化されていないことはわかっています)。同時アクセスがどのように処理されるか知りたいですか?
Uri uri = Uri.parse("content://sms/inbox");
mCursor = getContentResolver().query(uri, null, null, null,null);
mCursor.moveToFirst();
//I display the first sms. The code is not shown here.
//As the user scrolls the SMS-es other SMS-es are shown
//by moving the cursor
このコードに問題があります。SMS-es は、必要な権限を持つ他のアプリで削除できます。カーソルが指している SMS を他の SMS アプリが削除すると、カーソルはどうなりますか。たとえば、10 個の SMS があり (最新が最初)、カーソルが 9 番目の SMS にあるとします。他の SMS アプリは、最後の 3 つの SMS を削除します。これは私のカーソルをぶら下げませんか?
while(cursor.moveToNext()) {
//read the fields. What if somebody deletes the SMS-es
//after moveToNext evaluates to true but before I read fields?
}
結果セットのすべての行がキャッシュされておらず、これが問題を引き起こしていると思います。