安卓:从SQLiteDatabase其他类访问的信息? [英] ANDROID: Accessing information from SQLiteDatabase in other classes?

查看:111
本文介绍了安卓:从SQLiteDatabase其他类访问的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包括数据库,一个光标,并且所有的存取方法数据库的信息的单独的类。我输入光标到所有的类更新或使用该数据库。不过,我得到一个运行时错误,每当我试图启动一个使用数据库的意图。对可能发生的事任何想法?

I have a separate class that includes the database, a cursor, and all the accessor methods for database information. I import the cursor into all the classes that update or use the database. However, I get a runtime error whenever I try to start an intent that uses the database. Any ideas on what might be happening?

推荐答案

您不能从另一个应用程序访问数据库,你应该做的是,如果你想将这些数据暴露给其他应用程序创建的ContentProvider。

You can't access the database from another application, what you should do is create a ContentProvider if you want to expose this data to other apps.

如果你想从你的应用程序中访问它,创建一个包装DBHelper的访问SQLLite数据库还挺类,这个是唯一一类在你的应用程序触摸数据库直接,那么暴露的方法来选择,更新,删除等其他类不需要知道数据库,他们只是处理DBHelper类和Java对象。

If you're trying to access it from within your application, create a wrapper DBHelper kinda class that access the SQLLite db, and have this be the ONLY class in your app touching the database directly, then expose methods to select, update, delete, etc. Other classes don't need to know about the database, they just deal with the DBHelper class and Java objects.

这篇关于安卓:从SQLiteDatabase其他类访问的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆