title: Android Improve SQLite Performance Optimise
body: <p>I have an onCreate that currently opens an sqlite database and reads off 4 values. I then have a conditional and depending on what activity has sent it there it either displays those values or updates two values and then displays the other.</p>
  
  <p>Now if I run this activity without updating the database it is lightning fast. Whereas if I run two queries to write to the database it can be sluggish. Is there anything I am able to do to optimise this.</p>
  
  <p>The problem is the display stays on the previous activity until the sqlite updating has completed. This seems to be the problem.</p>
  
  <p>Sorry for what is most likely a rubbish explanation. Please feel free to ask me to better describe anything.</p>
  
  <p>Any help appreciated.</p>
  
  <pre><code>    public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      setContentView(R.layout.reason);
  
    //Opens DB connection
  
      type = b.getString("TYPE");
  
  
      get();
      if(type.equals("next")){ update();}
      db.close();
      }
  
  
      public void get(){      
  Cursor b = db.rawQuery("SELECT * FROM " +
          DB_TABLE2 +" WHERE _id='1'" , null);
  b.moveToFirst();
  id = b.getInt(b.getColumnIndex("nextq"));
      nextvalue = b.getInt(b.getColumnIndex(type));
  if(nextvalue==0){nextvalue=1;}
  b.close();           
  nextvalue ++;
      }
  
      public void update(){   
  db.execSQL("UPDATE "
          + DB_TABLE2
          + " SET nextq='" + nextvalue + "'"
          + " WHERE _id='1'");
  db.execSQL("UPDATE "
          + DB_TABLE
          + " SET answered_correctly='" + anscorrect +"' , open ='1' WHERE _id='" + id + "'");
      }
  </code></pre>