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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:56:51+00:00 2026-05-15T18:56:51+00:00

I have an android application using an SQLite database. I open the database when

  • 0

I have an android application using an SQLite database. I open the database when the application starts, but never close it as it is in constant use.

What is the best way to tell the database to flush all its changes to permanent storage? Do I need to just close it and re-open or is there a more efficient way?

My problem is that when testing on a phone, turning the phone off after a number of writes sometimes causes the database to loose the most recent updates when the application is restarted, which is obviously unacceptable for a database system.

Since I cannot find out how to capture the application close event I cannot know when to manually close the database.

  • 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-15T18:56:51+00:00Added an answer on May 15, 2026 at 6:56 pm

    I open the database when the application starts, but never close it as it is in constant use.

    Don’t do that. You are apparently ignoring all the errors that are appearing in LogCat complaining that you are leaking database connections.

    What is the best way to tell the
    database to flush all its changes to
    permanent storage?

    It will do that automatically at the end of a transaction. By default, each individual SQL operation (e.g., insert) is a transaction.

    Do I need to just close it and re-open
    or is there a more efficient way?

    You should close your database at some point (e.g., onDestroy() of the service that is mediating your database).

    My problem is that when testing on a
    phone, turning the phone off after a
    number of writes sometimes causes the
    database to loose the most recent
    updates when the application is
    restarted, which is obviously
    unacceptable for a database system.

    If you can create a sample project that demonstrates the problem even after you are properly closing your database connection, post it to the Android issue tracker.

    Since I cannot find out how to capture
    the application close event I cannot
    know when to manually close the
    database.

    Close it when all activities have unbound from the service that is mediating the database connection, triggering that service’s onDestroy() method.

    Or, open a fresh connection in each component that needs access to the database, and use Java synchronization to ensure two threads do not try to simultaneously use the database (if needed).

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

Sidebar

Related Questions

I started using a SQLite database in my android application. Very simple to use
Hi i am developing android application, And now i have to use sqlite database
I have developed the android phonegap application using html page and css. But My
I'm using SQLite in an Android application. In all of my tables I have
I have a pre-baked sqlite database that I want to use in my Android
I am developing an application in which I have to use existing database but
I have an SQLite database within my Android application, which stores dates as integers.
I have an android application with a SQLite database and I am trying to
I am using a SQLite database on an Android application and the getAll method
I have been using an SQLite database in the application I am developing for

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.