title: Android Sqlite Database record deleted after updating the apk version
body: <p>I have tried to implement the persistence layer of my application so that after updating the apk via Google Play, the database record can be maintained. When it comes ti the implementation, it erases all data after updating my apk version. Would you please tell me the way to back up and restore the sqlite records? </p>
  
  <p>The below is my code</p>
  
  <pre><code> private static final String DATABASE_NAME = "hkgadddlden.sqlite";
  
      private static final int DATABASE_VERSION = 6;
  
      private Dao&lt;History, Integer&gt; hDao = null;
      private Dao&lt;Favourite, Integer&gt; fDao = null;
      private Dao&lt;Lm, Integer&gt; lDao = null;
      private Dao&lt;iconPlus, Integer&gt; iDao = null;
  
  
      public DatabaseHelper(Context context)
      {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override
      public void onCreate(SQLiteDatabase database,ConnectionSource connectionSource)
      {
  //      database.execSQL("create table history(t_id integer, topic text, page integer, PRIMARY KEY(t_id));");
  //      database.execSQL("create table lm(t_id integer, PRIMARY KEY(t_id));");
  //      database.execSQL("create table favourites(t_id integer, PRIMARY KEY(t_id));");
  
          try
          {
              TableUtils.createTable(connectionSource, History.class);
              TableUtils.createTable(connectionSource, Favourite.class);
              TableUtils.createTable(connectionSource, Lm.class); 
              TableUtils.createTable(connectionSource, iconPlus.class);            
          }
          catch (SQLException e)
          {
              Log.e(DatabaseHelper.class.getName(), "Can't create database", e);
              throw new RuntimeException(e);
          }
          catch (java.sql.SQLException e)
          {
              e.printStackTrace();
          }
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db,ConnectionSource connectionSource, int oldVersion, int newVersion)
      {
          db.execSQL("DROP TABLE IF EXISTS history"); //刪除舊有的資料表
          db.execSQL("DROP TABLE IF EXISTS lm");
          db.execSQL("DROP TABLE IF EXISTS favourite");
          db.execSQL("DROP TABLE IF EXISTS iconPlus");        
          onCreate(db, connectionSource);
  
          try
          {
              List&lt;String&gt; allSql = new ArrayList&lt;String&gt;();
              for (String sql : allSql)
              {
                  db.execSQL(sql);
              }
          }
          catch (SQLException e)
          {
              Log.e(DatabaseHelper.class.getName(), "exception during onUpgrade", e);
              throw new RuntimeException(e);
          }
  
      }
  </code></pre>