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 6899657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:26:56+00:00 2026-05-27T07:26:56+00:00

I am trying to make multithread use of one sqlite database on Android. I

  • 0

I am trying to make multithread use of one sqlite database on Android.
I have the following situation :

Activity A : it has 10 threads which use DB ,but uses only one SQLiteDatabase

Activity B : has 10 threads which use DB ,but uses only one SQLiteDatabase

(the two SQLiteDatabase objects of the Activities are different)

The logic execution is the following :

  1. A calls B
  2. B inserts into the database and returns to A
  3. A display the result
  4. A try to erase what B inserted but fails .

A can erase old things ,but the new objects that B just inserted fail,if I restart the application ,A is able to erase the objects that previously couldn’t.
Should I use the same SQLiteDatabase for the two Activities ,and if is this the case how to pass this object to Activity B ?

Activity A thread code :

private class Delete_Task extends AsyncTask {

    private Context mContext;

    private DatabaseManager mDB;

    public DeleteEvent_Task(Context mContext,DatabaseManager DB) {
        this.mContext = mContext;
        this.mDB = DB;
    }

    @Override
    protected Void doInBackground(Long... params) {
        long id = params[0];

        this.mDB.delete(id);

        return null;
    }
}

Activity B thread code :

private class Update_Task extends AsyncTask< Object, Void, Void > {

    private Context mContext;


    public Update_Task(Context mContext)
    {
        this.mContext = mContext;
    }

    @Override
    protected Void doInBackground(Event... params) {
        Object e = params[0];

        DatabaseManager DB = new DatabaseManager(this.mContext);

        if (e.getId() <= 0)
        {           
            DB.add(e);
        }
        else
        {

            DB.update(e.getId(), e);
        }
        DB.close();

        return null;
    }       
}
  • 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-27T07:26:56+00:00Added an answer on May 27, 2026 at 7:26 am

    By far the simplest thing to do is open the database connection once, on application startup, and share this connection throughout your code without ever closing it. Provided you use a single connection, all reads and writes will be correctly serialized so you don’t need to worry about it.

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

Sidebar

Related Questions

Trying to make a MySQL-based application support MS SQL, I ran into the following
trying to make a page which will recursively call a function until a limit
While trying to make one of my python applications a bit more robust in
im trying make one replace in string from a array but this dont work
I'm trying make this code which is from a Dictionary of Arrays (CODE) from
I'm trying make one treeView with infinite subgroups. I can add my groups but
i have written a library with some classes that make use of qt object
Trying to make a quick and dirty news system. Have a basic XML file.
trying to make one horizontal box.. inside that update limits. if u see the
I have an application that I'm trying to make multithreaded. Each thread will access

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.