开发者

How to use SQLiteOpenHelper without or less restrictive use of Context?

If you extend SQLiteOpenHelper, for the Constructor you have to use a Context. I am wondering if there is a way to leave this out, and be able to work with database tables without a Context.

Or at least be least restrictive, I mean a way of project/class structure that will m开发者_如何学Pythonake history the several context passings I have to do now.

As it is my application has several level of classes, chained in each other, and there are a few that connects to the database, but have no whatsoever influence on the interface, so they don't actually need the Context.

Are you creating your classes in the way that you pass each time a Context to them?

If not, how you do, how you reuse a Context in a short class?


I am wondering if there is a way to leave this out, and be able to work with database tables without a Context.

Call openDatabase() on SQLiteDatabase.

As it is my application has several level of classes, chained in each other

Please remember that this is a mobile phone you are developing for. Too many abstraction layers will hamper performance.

Are you creating your classes in the way that you pass each time a Context to them?

Sometimes yes, sometimes no.

If not, how you do, how you reuse a Context in a short class?

Use inner classes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜