困惑CursorLoaders并使用它们使用自定义SQLiteOpenHelper [英] Confused about CursorLoaders and using them with a custom SQLiteOpenHelper

查看:216
本文介绍了困惑CursorLoaders并使用它们使用自定义SQLiteOpenHelper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,允许人们设置报警,他们需要做的各项工作任务。我目前的计划是将所有相关的数据存储到一个SQLite数据库。为此,我创建了扩展SQLiteOpenHelper的类和方法来处理一切,我期望有采取的CRUD填充它,知道它的通常是一个坏主意,做所有的处理一个线程,我抬起头的方式来独立的线程之间的工作,发现CursorLoader和LoaderManager,这似乎理想的,因为他们可以在Android兼容性库收录。然而,LoaderManager似乎都需要一个ContentProvider的由教程中的文档去,我的天堂吨真的看到了需要做ContentProviders因为我不打算允许其他应用程序访问数据的任何东西。如果没有一个ContentProvider的,我不知道怎么我应该得到一个开放的为我的数据库送入CursorLoader。有没有办法让我继续使用我的课,扩展SQLiteOpenHelper,并且仍然实现LoaderManager让我把所有的填充ListFragments与我的光标从UI线程的?

解决方案
  

有没有办法让我继续使用我的课,扩展SQLiteOpenHelper,并且仍然实现LoaderManager让我把所有的填充ListFragments与我的光标从UI线程的?

您只需要一个不同的装载机的实施,一个不涉及的ContentProvider 。它只是恰巧,我写这些之一。

I'm writing an app that allows people to set alarms for various tasks that they need to do. My current plan is to store all the relevant data into an SQLite database. To that end, I have created a class that extends SQLiteOpenHelper and filled it with methods to handle all the CRUD that I'd expect to have to take in. Knowing that it's generally a bad idea to do all the processing on one thread, I looked up ways to separate the work between threads and found CursorLoader and LoaderManager, which seemed ideal as they were available in the Android Compatibility Library. However, LoaderManager seems to require a ContentProvider going by the tutorial in the documentation, and I haven't really seen a need to do anything with ContentProviders since I wasn't planning on allowing other apps to access the data. Without a ContentProvider, I don't know how I'm supposed to get a Uri for my databases to feed into the CursorLoader. Is there a way for me to keep using my class that extends SQLiteOpenHelper and still implement LoaderManager to allow me to keep all the populating ListFragments with my cursor off of the UI thread?

解决方案

Is there a way for me to keep using my class that extends SQLiteOpenHelper and still implement LoaderManager to allow me to keep all the populating ListFragments with my cursor off of the UI thread?

You just need a different Loader implementation, one that does not involve a ContentProvider. It just so happens that I wrote one of those.

这篇关于困惑CursorLoaders并使用它们使用自定义SQLiteOpenHelper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆