質問

I'm new to android development and I've got a little stuck with the new API, I can't seem to find a tutorial to help.

I've got a database with a SQLOpenHelper and a Database adapter that I've seen used in many examples, such as this. I want to hook up the data into a list, so have created a ListFragment. The tutorials that I've seen use the startManagingCursor(c) method in Activity, however the documentation says that this is depreciated and to use CursorLoader.

To use the CursorLoader it looks like I need a uri, which implies I need a content provider. I don't need a content provider for my app, so I'm not sure how to implement this or what is the correct/ recommended way.

A shove in the right direction would be great!

役に立ちましたか?

解決

From what I've read and understood, the Android team encourages the use of a ContentProvider that sits in front of your database. As you can see with CursorLoader, the Android API is also encouraging this usage pattern.

Letting aside discussions if this is the best approach for small apps, I think you should not fight the API and go with a ContentProvider. CursorLoader handles a lot of stuff for you and I find it works really well.

他のヒント

Some points that I need to add here

Yes, use ContentProvider, that's Google teams encounge to do. Remember the three layers in database book:storage, logic,application. Contentprovider act as the logic.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top