title: How to close the database connection in Android
body: <p>Currently working on database part of android project. The main aim of the project is to parse  the XML file and store the database as its parsing. I am opening the database and inserting the data in database. But when I try to change the activity it crashes on close() function of database.
  I know I am doing something wrong here. If anyone can help me here it will be great.</p>
  
  <p>/<strong>*<em>DatabaseManager.java</em>*</strong>/</p>
  
  <pre><code>    SQLiteDatabase db;
  public DatabaseManager(Context context){
      this.context = context;
  
      db = context.openOrCreateDatabase(DATABASE_NAME, 0, null);
      }
  
      public void close(){
      if ( db != null )
      {
          db.close();
      }
      }
  </code></pre>
  
  <p>/<strong>**<em>Activity.java</em>**</strong>/</p>
  
  <pre><code> public void onCreate(Bundle savedInstanceState) {
  
      try{
          super.onCreate(savedInstanceState);
          DB = new DatabaseManager(this);
       }
    }
  
   public void onDestroy(){
       super.onDestroy();
  
      if(DB!=null)
          DB.close();
   }
  </code></pre>
  
  <p>Errors:</p>
  
  <pre><code> E/Database(676): close() was never explicitly called on database '/data/data/org.com.android/databases/MainSQLite.db' 
  enter code here
  </code></pre>