android - 尝试重新查询已经关闭的游标

标签 android sqlite cursor illegalstateexception

我正在做简单的查询,例如:

Cursor c = databaseHelper.getReadableDatabase().rawQuery("select " + MyTable.TABLE_FIELD.getColumnName() + " from " + MyTable.TABLE_NAME, null);

之后,我提取所需的数据并填充一些 View 。

c.close();

一切都按预期进行。我有一个共享 Intent ,希望发送一封包含所显示的一些信息的电子邮件。电子邮件应用程序发送电子邮件或关闭并且我的 Activity 恢复“活力”后,会引发 java.lang.IllegalStateException 。 仅在这种情况下才会引发此异常,如果我将其发送到后台然后再次调用它,则不会引发此异常。我什至想打开 YouTube 并播放视频,但没有抛出此异常...

我真的不知道为什么会这样。

感谢您的宝贵时间。

ps:我尝试过 //c.close(); 但它也不起作用。

最佳答案

您可以使用c.requery(),但它在 API 级别 11 中已被弃用。

Don't use this. Just request a new cursor, so you can do this asynchronously and update your list view once the new cursor comes back.

Performs the query that created the cursor again, refreshing its contents. This may be done at any time, including after a call to deactivate(). Since this method could execute a query on the database and potentially take a while, it could cause ANR if it is called on Main (UI) thread. A warning is printed if this method is being executed on Main thread.

关于android - 尝试重新查询已经关闭的游标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16192728/

相关文章:

css - 光标:Mac Chrome 上的指针问题

css - 在 CSS 中设置自定义指针

android - 获取从 ListView 中选择的联系人的详细信息

android - 无法让 ADB 识别我的星系

Android:从路径创建投影

jquery - 在图像中输入区域时光标图像不起作用

java - 在 Java-Android 中设置链接可点击

python - 请求中的条件

mysql - Sqlite 查询创建问题

来自 SQLite 的 Android 游标在方法调用时崩溃