开发者

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

开发者 https://www.devze.com 2023-04-13 07:08 出处:网络
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 -

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 the开发者_如何学JAVAre a way to have both ContentProvider and direct access to database in one application?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消