Two content providers accessing the very same database

南笙酒味 提交于 2019-12-23 17:06:57

问题


Hi all!

I wonder if there is a generally preferred implementation paradigm to respect if one want's two completely different Android applications to access and operate on the same database? Is it recommended or even technically possible to do this at all? What would such an architecture look like?

As of now I'm considering to let the two applications implement their own ContentProviders (both ContentProviders will access the same database, guaranteed never simultaneously, though). I have also thought of building one common content provider and let both applications use that one when accessing the database. I prefer the first example but haven't completely discarded the later.

RATIONALE:
I have two applications which need to access a common database. The database itself stores data but also describes the relationship between the data rows, typically describing a set of "forms" where the form content; UI elements like text boxes, buttons and different kinds of lists, is customizable. Both applications use this "description data" in the database to generate parts of the respective application UI during runtime.

Hence, there are two aspects of the two applications: one "administrative" aspect (managing the data structure and relationship between the data rows) and one "generic user" aspect (reading/modifying the actual data values). It's a deliberate choice to separate these two aspects in separate applications.

NOTE! The data values are separated from the data structure, i.e. the values are stored in one separate table and the structure is described in another table. This means that the two applications will essentially modify two different tables in the same database and they will never modify "the other table", so to speak.

Any thoughts are greatly appreciated. The application is yet on a planning stage, so, now is the time to make fundamental changes.


回答1:


Dbm,

Yes, it is accepted, encouraged and possible to do on Android. You do have a 3rd option (that will no doubt get me some burning commentary) and that's to put the ContentProvider (1) in an APK all of it's own. But, given that you only have 2 types, you can flip a quarter over which apk it is hosted by. I would choose the admin app, but that is subjective on my part.

If you are going to the trouble of creating two applications then you have "a priori" knowledge of what the behavior of each will do, and what kind of data that each can operate. Therefore I would conclude a single CP interface and just constrain what each app calls given the behavior you've described.

Frank



来源:https://stackoverflow.com/questions/4842218/two-content-providers-accessing-the-very-same-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!