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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:16:17+00:00 2026-05-23T02:16:17+00:00

I have an app where I store some data in a SQLIte database. And

  • 0

I have an app where I store some data in a SQLIte database.
And what I’m trying to do is to get my DB opened only once at the start of my app and then use the same instance of my DB.

The idea is not to open my DB in every activity I need it.

One of the solutions I got was this-create a class that extends Application and then open the DB there:

This is how the code looks like:

public class MyApplication extends Application{

private static DBAdapter db;

public void onCreate()
{

    db=new DBAdapter(getApplicationContext());
    db.createDatabase();
    db.openDataBase();
}

public static DBAdapter getDatabaseAdapter()
{
    return db;
}

}

So in every activity of my app where I need to connect with my DB I do something like:

MyApplication myApplication = (MyApplication) this.getApplication();
DBAdapter db= myApplication.getDatabaseAdapter();

But I’m not very sure if my DB gets opened only at the beginning of my app…or it gets opened everytime I do this:

  MyApplication myApplication = (MyApplication) this.getApplication();

?

Or if anyone has a better solution please tell me:).Thank u

  • 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-23T02:16:18+00:00Added an answer on May 23, 2026 at 2:16 am

    It will be opened only once because you are calling it in onCreate method of Application class which will be called when the application is starting, before any other application objects have been created. You can look at one of my project here is link.

    Hope this help.

    EDIT: About Application Class : Android will automatically create an instance of that class and make it available for your entire application. You can access it from any context using the Context.getApplicationContext(). So there will be only one instance of Application which will be shared.

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

Sidebar

Related Questions

I have an iOS app that stores some data in a sqlite database. The
My iphone app uses a SQLite database to store data. I have a table
I have some data that I want to store somewhere in my Rails app
I have a Core Data-based iPhone app with a pre-populated read-only database. What protection
I have some sensitive data that is stored in SQLite for an Android app.
I have an app which stores data in a SQLite database, when the app
I have an app the store some data in the keychains. Now I want
I have some things in my app that I need to store, in order
I'm using PS to store data in my app. I think I have a
I have some XML data retrieved from a web service that I use to

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.