title: Android get context in database
body: <p>I have one database and I've created a <code>Database</code> class that has a <code>private static class DbHelper extends SQLiteOpenHelper</code> to help me manage my database.</p>
  
  <p>This database is access from four different activities. </p>
  
  <p>I have this <code>public void onCreate(SQLiteDatabase db)</code> that it's what creates my database tables and adds values to those tables. Since the program only enter here the first time the user runs the app, I want to create a <code>ProgressDialog</code>.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>Override
  public void onCreate(SQLiteDatabase db) {
  
      ProgressDialog progresso = ProgressDialog.show(context, "Info", "Loading DB" );
      // Code to create the tables and add the values
      progress.dismiss();
  }
  </code></pre>
  
  <p>Got 2 questions.</p>
  
  <p>First:</p>
  
  <p>Since this can be accessed from 4 different activities how can I get the context?
  Making:</p>
  
  <pre><code>Context context = getAplicationContext();
  </code></pre>
  
  <p>Second:</p>
  
  <p>Why can't I use strings from strings.xml?
  I can't make this:</p>
  
  <pre><code>ProgressDialog progresso = ProgressDialog.show(context, getString(R.string.driProgressTitle), getString(R.string.driProgressMessage) );
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>public class Database {
      ProgressDialog progresso;
      private DbHelper DBHelper;
      private final Context Context;
      private SQLiteDatabase BaseDados;
  
      private static class DbHelper extends SQLiteOpenHelper {
  
          public DbHelper(Context context) {
              super(context, BD_NAME, null, BD_VERSION);
              // TODO Auto-generated method stub
          }
  
          @Override
          public void onCreate(SQLiteDatabase db) {
  
          // Whanted to show here the progress dialog
          new loadDB().execute();
  
          // Creates the table and adds the values
  
          }
  
          @Override
          public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVesion) {
              db.execSQL("DROP TABLE IF EXISTS MYTABLE");
              onCreate(db);
          }
  
      }
  
      public Database(Context c) {
          Context = c;
      }
  
      public Database open() throws SQLException {
          DBHelper = new DbHelper(Context);
          BaseDados = DBHelper.getWritableDatabase();
          return this;
      }
  
      public void close() {
          DBHelper.close();
      }
  
      public Cursor getData(int tipo, long groupId, String query[]) {
          // Performs the querys to my database
      }
      return null;
  }
  
      public class loadDB extends AsyncTask&lt;Void, Void, Integer&gt; {
  
          @Override
          protected Integer doInBackground(Void... params) {
              progresso = ProgressDialog.show(Context, Context.getString(R.string.ProgressTitle), Context.getString(R.string.ProgressMessage) );
              return 1;
          }
  
          @Override
          protected void onPostExecute(Integer result) {
              progresso.dismiss();
              super.onPostExecute(result);
          }
      }
  }
  </code></pre>
  
  <p>With the above code I'm getting this error <code>No enclosing instance of type Database is accessible. Must qualify the allocation with an enclosing instance of type Database (e.g. x.new A() where x is an instance of Database).</code> in <code>new loadDB().execute();</code>.</p>