怎样在子线程中操作数据库自己写的待办事项功能,希望能在距离具体设置时间的某个时间段给用户提醒。(比方说设置该事项1月2号,希望在1月1号某个时间提醒)。
我个人的思路是,建一个service,然后用ContentObserve监听数据库,为了效率考虑,想新建一个子线程完成。
问题是:想在子线程中查询数据库,但在子线程调用managedQuery方法时会在获取相应的contentResolver时抛出空指针异常。想问问应该如何在子线程中操作数据库,还请各位不吝赐教,谢谢。
我个人的思路是,建一个service,然后用ContentObserve监听数据库,为了效率考虑,想新建一个子线程完成。
问题是:想在子线程中查询数据库,但在子线程调用managedQuery方法时会在获取相应的contentResolver时抛出空指针异常。想问问应该如何在子线程中操作数据库,还请各位不吝赐教,谢谢。
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.