How to organize database access code in Android project? -


I have created a ContentProvider for my main squat table, the following is very much from SDK (although I'm not sure I Never disclose my data in other applications) However, I need to create many other non-trivial queries on that and other tables and views. A good example is to remove figures from base data, average, total etc. The question will be.

So what's the best place for this code in the Android project? How should the provider relate to URI-based data access and be connected? Is there a good example?

From the point of view of the maintenance, I think the provider is the model of the correct data access code and the experience Worked on a large application, eventually the application would grow up to that point where some data provider should come out through the model (for example to start services to apply), he said that highlighting many different views of your data There may be a lot of work in the provider model Is obtained.

If you wanted to go the route, then I think carefully how you highlight the data through the URL, and usually the complexity you talk about, using the sub-directory Can be managed to represent different views of the data. (

If you wish to avoid the provider model, then implementing the DA class is quite simple. Usually an SQLiteOpenHelper is creatd as an internal class for the DA class (open accessory support providers basic version) and an example of this class is used to create database connections in the DA functions. There are many examples in the Android source code. Look at the implementation of any provider, perhaps most relevant because it uses very complex searches for the provider, for example, which is not a content provider with source code


Comments