惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - 清炒白菜

Android的匿名Handler类引起的内存泄露 计算2个经纬度之间的距离 用bcp导入DateTime类型的数据 Linux下提示“omitting directory”错误的解决办法 Android的"返回“功能 EditText获得焦点后,如何关闭软键盘 获取当前Activity的Root View 用代码动态设置ImageView的align布局 Android中Sqlite数据库多线程并发问题 [转]Java的数组(Array)、Vector、ArrayList、HashMap的异同 HTML中element.style取值问题 用bcp导入大量数据(代替INSERT) ajax跨域访问问题 又一款分布式版本控制工具Mercurial bcp导入导出数据发生异常解决方案 - 清炒白菜 - 博客园 导出Google Reader中加星的内容项 - 清炒白菜 - 博客园 在win下使用GIT dotNet 自带线程池与HTTP访问的若干疑问 解决"the database principal owns a schema in the database and cannot be dropped"问题
Unable to resume activity : android.database.StaleDataException: Attempted to access a cursor after it has been closed. 异常
清炒白菜 · 2013-05-17 · via 博客园 - 清炒白菜

2013-05-17 19:21  清炒白菜  阅读(4294)  评论()    收藏  举报

一般用Cursor后, 就立即close()了,但是在用managedQuery的时候, 却不能主动调用close()方法, 否则在Android 4.0+的系统上, 会发生崩溃

google的文档是这么写的

Warning: Do not call close() on a cursor obtained using this method, because the activity will do that for you at the appropriate time. However, if you call stopManagingCursor(Cursor) on a cursor from a managed query, the system will not automatically close the cursor and, in that case, you must call close().

也有人说用下面的方法可以避免这个问题

这个问题其实很简单  估计大家在查询数据库的时候用的是这个函数  
viedoCursor = context.managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoColumns,null, null, null);
只要换成这样就可以了:
ContentResolver cr = context.getContentResolver();
viedoCursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoColumns,null, null, null);
我也是无意间发现有着两种写法的 然后试了一下问题就解决了

参考:http://stackoverflow.com/questions/9696868/unable-to-resume-activity-error

http://changyy.pixnet.net/blog/post/31238721-android-%E9%96%8B%E7%99%BC%E7%AD%86%E8%A8%98---unable-to-resume-activity-%3A-android.d