2

我正在编写一个 Android 短信应用程序。我正在使用“content://sms/inbox”阅读现有的 SMS-es(我知道它没有记录)。我想知道如何处理并发访问?

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 可以被其他具有必要权限的应用程序删除。如果其他短信应用程序删除了我光标指向的短信,光标会发生什么情况。例如,假设我有 10 条短信(最新的是第一条),我的光标位于第 9 条短信。其他一些短信应用程序会删除最后 3 条短信。这不会使我的光标悬空吗?

while(cursor.moveToNext()) {
//read the fields. What if somebody deletes the SMS-es
//after moveToNext evaluates to true but before I read fields?
}

我认为结果集中的所有行都没有缓存,这会带来问题。

4

0 回答 0