简体   繁体   中英

How to Pre-populate An Android Database Backed by ContentProvider

I am loving the flexibility offered by ContentProvider, obviously ContentProvider is the favored route to go for an Android database, however, how does one efficiently populate the resulting database?

For instance, let's say I am creating an RSS reader with links to 100 feeds. The feeds themselves should be in the database at launch, how would I populate these feeds into the database?

Would I have to write 100 queries based on getContentResolver.insert() to do this? That approach seems complicated and unnecessary.

Moreover, how would one review the database content created to ensure things are going as planned? I can't simply find the database like one would with a SQL database created for the app.

Thank you for the suggestions!

obviously ContentProvider is the favored route to go for an Android database

You are welcome to your opinion.

how does one efficiently populate the resulting database?

In terms of pre-population, you would do it the same way that you would pre-populate a database that is not fronted by a ContentProvider . I would recommend that you use SQLiteAssetHelper .

I can't simply find the database like one would with a SQL database created for the app.

Since you are the one creating the database and the ContentProvider , you most certainly know where the database is and what you named it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM