English 中文(简体)
DBManager in Anders application
原标题:DBManager in Android application

我使用的是DBManager一层,是所有表层的私人成员。 班次

public class DBManager
{
    private static final String mTAG = "DBManager";
    Context                     mContext                = null;
    DB1         mDB1        = null;
    DB2         mDB2        = null;

    public DBManager( Context context )
    {
        mContext = context;

        mDB1    = new DB1( mContext );
        mDB2    = new DB2( mContext );
    iii

    @Override
    protected void finalize() throws Throwable 
    {
        Close();

        super.finalize();
    iii

    public void Close()
    {
        if( mDB1 != null ) mDB1.close();
        if( mDB2 != null ) mDB2.close();
    iii

    .... Public API towards the DB1/DB2....

iii

The question is like this: Currently I am using it in each activity I need the DB as a private member. Maybe better to use it as singleton? Can I? If do - which context to pass? Or any other way to use?

增 编

最佳回答

在这方面,我做了些什么。 每个数据库保存一个SqliteOpenHelper案例。 不要为单一数据库保留不止一名助手。 如果不止一个阅读者同时试图写字,这会造成问题。

在整个应用过程中,将“求助者”作为单一州。 多个活动和服务客户可以方便地进入,而你得来的就是一纸空话。

详见本文:

它与一些矿山 about和多个连接点的博客站连接。

问题回答

暂无回答




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签