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

  • Home
  • SEARCH
  • 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 3634656
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:48:23+00:00 2026-05-19T00:48:23+00:00

I am making a IM client for android and I am working with databases

  • 0

I am making a IM client for android and I am working with databases for storing the contacts and other info’s… In my app I have an activity and one service. I need to open three databases in the same time both on the service and on the activity.

I use three database because I want the databases to be managed more easily without having problems with the synchronization of writing in them. (as far as I know I need to write in the database synchronously because it may crush).

To manage the databases from the service and from the activity in the same time, I thought that a singleton or a static class of DatabaseHelper could help me…

So I have started to make a test by making two databasehelper global objects in the activity, each one opens a diferent database, after running the project i’ve noticed that the last opened database remains opened in both objects :((, why is this happening?

Can somebody sugest me how can i make this work?
Thank you!

L.E.: after more tests, I made a Static object of databasehelper, open a service from which I take the database object from activity and in the same time i made two for statements, one in activity and one in service that run from 0 to 3000 and adds some values into the same database and then it reads the database.

After this run i noticed that the database is still in feet and running without errors. The strange thing is that the service for is running only after the activity for finishes the job. Why is that?
Thank you!

  • 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-19T00:48:24+00:00Added an answer on May 19, 2026 at 12:48 am

    I have a DatabaseAdapter class which contains two databases which are opened together.

    public class DatabaseAdapter {
        /** Identifier for the internal database */
        public static final int             INTERNAL            = 0;
        /** Identifier for the external database */
        public static final int             EXTERNAL                = 1;
    
        private final SQLiteOpenHelper[]    mDatabaseManager    = new SQLiteOpenHelper[2];
        private final SQLiteDatabase[]      mDatabases          = new SQLiteDatabase[2];
    
        /**
         * Constructs the database and open it.
         */
        public DatabaseAdapter() {
            // Open the internal_db
            mDatabaseManager[INTERNAL] = new InternalDatabaseManager(MyApplication.getInstance());
            mDatabases[INTERNAL] = mDatabaseManager[INTERNAL].getWritableDatabase();
        }
    
        /**
         * Checks the database state and throws an {@link IllegalStateException} if database isn't open.
         * Should always be used before starting to access the database.
         * 
         * @param type Type of the database. Can be INTERNAL or EXTERNAL.
         */
        public void checkDbState(int type) {
            if (mDatabases[type] == null || !mDatabases[type].isOpen()) {
                throw new IllegalStateException("The database has not been opened");
            }
        }
    
        /**
         * Closes the database of the given type.
         * 
         * @param type Type of the database. Can be INTERNAL or EXTERNAL.
         */
        public void close(int type) {
            if (mDatabases[type].isOpen()) {
                mDatabases[type].close();
                mDatabases[type] = null;
                if (mDatabaseManager[type] != null) {
                    mDatabaseManager[type].close();
                    mDatabaseManager[type] = null;
                }
            }
        }
    
        /**
         * @param type Type of the database. Can be INTERNAL or EXTERNAL.
         * @return true if the database is open, false otherwise.
         */
        public boolean isOpen(int type) {
            return mDatabases[type] != null && mDatabases[type].isOpen();
        }
    
        /**
         * Opens the default database.
         * 
         * @param type Type of the database. Can be INTERNAL or EXTERNAL.
         */
        public void open(int type) {
            switch (type) {
                case INTERNAL:
                    mDatabaseManager[INTERNAL] = new InternalDatabaseManager(MyApplication.getInstance());
                    if (!isOpen(INTERNAL)) {
                        mDatabases[INTERNAL] = mDatabaseManager[INTERNAL].getWritableDatabase();
                    }
                break;
                case EXTERNAL:
                    mDatabaseManager[EXTERNAL] = new ExternalDatabaseManager(MyApplication.getInstance(), Constants.EXTERNAL_DB_PATH, 1);
                    if (!isOpen(EXTERNAL)) {
                        mDatabases[EXTERNAL] = mDatabaseManager[EXTERNAL].getWritableDatabase();
                    }
                break;
            }
        }
    }
    

    to add a third one should be easy 🙂

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

Sidebar

Related Questions

I am working on making my client open another program by downloading the bytes
I'm making a twitter client, and I'm evaluating the various ways of protecting the
I'm making a twitter client, and I'm evaluating the various ways of protecting the
I am interested in making a Google Talk client using Python and would like
We are making a lab instrument using an ARM9/RTOS system. The client has asked
After making a few modifications to a rails app I am tinkering on, railroad
So I'm making an app where I want the users to be able add,
I'm creating a Spring WS client. I have a huge WSDL from a third-party
An app I'm working on interfaces with an existing application running on a remote
Making echo of a question around the web: Is the syntax for svn:ignore patterns

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.