怎样在子线程中操作数据库自己写的待办事项功能,希望能在距离具体设置时间的某个时间段给用户提醒。(比方说设置该事项1月2号,希望在1月1号某个时间提醒)。
我个人的思路是,建一个service,然后用ContentObserve监听数据库,为了效率考虑,想新建一个子线程完成。
问题是:想在子线程中查询数据库,但在子线程调用managedQuery方法时会在获取相应的contentResolver时抛出空指针异常。想问问应该如何在子线程中操作数据库,还请各位不吝赐教,谢谢。
我个人的思路是,建一个service,然后用ContentObserve监听数据库,为了效率考虑,想新建一个子线程完成。
问题是:想在子线程中查询数据库,但在子线程调用managedQuery方法时会在获取相应的contentResolver时抛出空指针异常。想问问应该如何在子线程中操作数据库,还请各位不吝赐教,谢谢。
解决方案 »
- android 多个页面如何共用同一组件
- 请问哪里有为个人开发者提供数据同步的服务。
- android 通讯录中多音字处理
- android网络播放器设计
- activity 传值给 service
- android sqlite,如何用代码创建2个数据库
- FileInputStream 、InputStreamReader 、BufferedReader有方法可以跳过前面的指定长度内容开始读取吗 ?
- 手机访问webservice的问题
- Android 4.1 sdk WebView question
- AndroidStudio目录结构问题
- 如何读写存储卡中的图片
- intent.setData 过时了的问题
com.googlegroups.android-developers You can just use ContentResolver.query() directly. managedQuery() is a simple wrapper on top of that, which also takes care of managing the cursor in conjunction with the activity's lifecycle. The lifecycle of a service is much simpler (and open-ended) so it doesn't make sense to have a managedQuery() method on it. On Jan 6, 3:20 pm, "[email protected]" <[email protected]> wrote: Hello How can i create a cursor from managedQuery(returns a cursor from a content provider, and updates automatically data from it), in a service. I need to access a database from a service, and insert some data, but before i have to verify that my data is correct. Or maybe there is something else, but and i don't see how. Please help.