Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6799219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:49:21+00:00 2026-05-26T18:49:21+00:00

I am using a DBManager layer, it holds as private member all all the

  • 0

I am using a DBManager layer, it holds as private member all all the SQLiteOpenHelpers for the tables. The class is as followed

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 );
    }

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

        super.finalize();
    }

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

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

}

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?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:49:22+00:00Added an answer on May 26, 2026 at 6:49 pm

    Here’s what I do. Keep one instance of SqliteOpenHelper per-database. Do not keep more than one Helper for a single database. This can cause issues with writes if more than one thread are trying to write at the same time.

    Keep the Helper instance as a singleton across your application process. Multiple Activity and Service clients can access it easily and you won’t have write lock issues.

    See here for details:

    http://www.touchlab.co/blog/single-sqlite-connection/

    It links to a few blog posts of mine about Sqlite and multiple connections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C#, I need a class called User that has a username, password, active
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Consider the following situation. I have 3 tables in a resource planning project(created using
Currently I'm using a separate DBConnectionManager class to handle my connection pooling, but I
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.