title: Updating the database doesn't work -Android
body: <p>I wrote some code to ensure that my database will be updated properly when I will release updates to my application.</p>
  
  <p>The problem is that the OnUpdate() function of the SQLiteOpenHelper is never called.
  Here is the code I wrote in the main activity - </p>
  
  <pre><code>    SharedPreferences DB_ver = getSharedPreferences(PREFS_NAME, 0);
      myDbHelper = new DataBaseHelper(con, DB_ver.getInt("DB_ver", 1));
      try {
          if(DB_ver.getInt("DB_ver", 1) !=getPackageManager().getPackageInfo(getPackageName(), 0).versionCode )
          {
                SharedPreferences.Editor editor = DB_ver.edit();
                editor.putInt("DB_ver", getPackageManager().getPackageInfo(getPackageName(), 0).versionCode);
          }
      } catch (NameNotFoundException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>Here is the constructor of SQLiteOpenHelper(which extends SQLiteOpenHelper) -</p>
  
  <pre><code>public DataBaseHelper(Context context,int ver_code) {       
      super(context, DB_NAME, null, ver_code);
      this.myContext = context;
  }   
  </code></pre>
  
  <p>Now I understood that the Super line is supposed to call the onUpgrade() function automatically, but it doesn't.</p>
  
  <p>I've tested the function onUpgrade() separately, and it works.</p>
  
  <p>Does anyone know what's the problem?</p>
  
  <p>Thanks! </p>