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

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The key piece of information to this question, and not… May 17, 2026 at 3:13 am
  • Editorial Team
    Editorial Team added an answer create table mytable2 like mytable; insert into mytable2 select max(id),… May 17, 2026 at 3:13 am
  • Editorial Team
    Editorial Team added an answer There is no simple completly unattended way of doing what… May 17, 2026 at 3:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using SQLite in an Android application. In all of my tables I have
I am using SQLite in a project used by an android application. Currently I
I'm working on an Android application that stores data in a SQLite database. My
I'm writing an Android application for RC Cars. It uses a SQLite database, and
I'm having a go at developing my first android application and have never really
I have been searching on google for information regarding application passwords and SQLite security
I guess many people already read this article: Using your own SQLite database in
I have an unfinished application, but I want to address now the future update
I have a single Android application that houses a suite of applications. I want
I'm developing an Android application using Android 1.5. I'm using an older version of

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.