Java 使用游标的并发访问

Java 使用游标的并发访问,java,android,sms,cursor,android-contentprovider,Java,Android,Sms,Cursor,Android Contentprovider,我正在写一个Android短信应用程序。我正在阅读已存在的SMS es,使用“content://sms/inbox“(我知道这是没有证件的)。我想知道如何处理并发访问 Uri uri = Uri.parse("content://sms/inbox"); mCursor = getContentResolver().query(uri, null, null, null,null); mCursor.moveToFirst(); //I display the first sms. The c

我正在写一个Android短信应用程序。我正在阅读已存在的SMS es,使用“content://sms/inbox“(我知道这是没有证件的)。我想知道如何处理并发访问

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条短信(最新的是第一条),我的光标在第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?
}

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

将光标数据保存到对象,关闭光标并使用保存的数据。每次都听取更改并重新刷新数据。