Is it possible to use ContentProvider and direct data access to Database in Android?

本秂侑毒 提交于 2019-12-11 15:13:51

问题


I have application that uses direct data access to it's Database. I have nothing to expose outside of it for other applications. As CommonsWare says somewhere on SO, "if you have nothing to expose - don't use ContentProvider". Now, I want to add widget to display a couple of strings from one of the tables, storing in Database. Should I refactor the direct access code to the ContentProvider pattern? Is there a way to use direct access to Database from widget? Is there a way to have both ContentProvider and direct access to database in one application?


回答1:


Now, I want to add widget to display a couple of strings from one of the tables, storing in Database.

I am going to assume that by "widget" you really mean "app widget".

Should I refactor the direct access code to the ContentProvider pattern?

You do not have to do this just because you are writing an app widget.

Is there a way to use direct access to Database from widget?

Sure, using the same mechanisms you are using anywhere else in your app.

Is there a way to have both ContentProvider and direct access to database in one application?

Yes, though you have to be a bit careful to make sure that you are using the same SQLiteDatabase object in both cases, so you do not run into threading issues.



来源:https://stackoverflow.com/questions/7772174/is-it-possible-to-use-contentprovider-and-direct-data-access-to-database-in-andr

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