title: opening and closing a sqlite database after using it everytime
body: <p>Is it a good practice to open and close the database for every database transaction operation? let me clear you more.</p>
  
  <p>I have two methods like</p>
  
  <pre><code>public SQLiteDatabase getDatabase() {
      if (database == null || !database.isOpen()) {
          database = getWritableDatabase();
      }
      return database;
  }
  
  public void closeDatabase() {
      if (database != null &amp;&amp; database.isOpen()) {
          database.close();
      }
  }
  </code></pre>
  
  <p>so every time, when I am updating/inserting or deleting, I am opening the database and closing it.</p>
  
  <pre><code> public void insert(...) {
        getDatabase().insert(...);
        closeDatabase();
   }
  
   public void update(...) {
        getDatabase().update(...);
        closeDatabase();
   }
  
   public void delete(...) {
        getDatabase().delete(...);
        closeDatabase();
   }
  </code></pre>
  
  <p>remember that all these methods are inside a class <code>DatabaseHelper</code> which is extending <code>SQLiteOpenHelper</code> and there is a global variable <code>private SQLiteDatabase database</code></p>
  
  <p>and I will perform these operations(insert/update/delete) more frequently.</p>
  
  <p>So my question is <code>Is it a good practice to open and close database for every transaction? if not, what is the good way? Where and When I have to close my database?</code></p>