Two snippets - use sqlite from both snippets, or pass details from one to the other?

Let's say I have a SQLite table that contains 10 columns of text like (20).

The ListFragment pulled 4 columns from the database and displayed them in the list using SimpleCursorAdapter.

Once selected, the ListFragment will pass the selected row_id to the DetailFragment where it would pull all 10 columns from the database for display (another query).

An alternative design would be to pull all the data required up front into the ListFragment (but only display what was needed) and pass everything to the DesignFragment via an intent or constructor. What I didn’t like about this option was that the list would contain additional data that it didn’t need, while the original option would mean a secondary call to the database.

What would be the preferred option?

Thank.

+3


source to share


1 answer


Well, I may not be an expert on this, but in my opinion it is best not to query the database over and over again.

Request the data once (assuming your database content is not very HUGE) and transfer it using Intent .



However, instead of passing them through Intents, I would personally advise you to create a Utility class to contain all the details of the database, and you can just initialize that class object once and then use the object wherever you need it. The only thing you need to keep in mind is that you need to update this object's data every time your database content is updated.

(For example, the official Android Android SDK uses the Utility class to store all user information, including access tokens and session IDs)

+1


source







All Articles