Reputation: 36484
Problem :
I have to create a number of tables for caching some amount of textual data, obtained by reading XMLs. These tables need to be created only once - on the initial run of the application. The data in the tables should be cleared after fixed time period. There should be a class exposed to other classes that would allow CRUD operations on this database.
Googling found me some links to tutorials for creating databases and Data Access logic.
I have some questions, please help:
Thanks.
Upvotes: 2
Views: 797
Reputation: 32930
The most simple approach in this case is to stick with ContentProviders. They allow you to perfectly separate your DB related logic (setup of DB tables, managing of DB upgrades, CRUD ops) from the rest of the app.
Rather than rewriting it here I'll link you to the post I've done here on this SO question: Android Database Access Design Approach
The data in the database is to be displayed in Lists. I have data in ArrayLists(created when parsing XML) as well as Database(after these lists are persisted). What adapter should I use to back the list up? Should I use ListAdapter or CursorAdapter?
Yep, the CursorAdapter is probably fine in this case. In your ListActivity you can then execute the query like
...
CursorAdapter adapter = managedQuery(....);
setListAdapter(adapter);
...
The refresh of the list will happen automatically if you implemented the ContentProvider correctly. Because in that case you will have a line like
...
getContext().getContentResolver().notifyChange(uri, null);
...
in your insert/update/delete methods which will notify the registered observers to update their data.
Upvotes: 1
Reputation: 5592
Upvotes: 1