title: How to call Application getDatabase in Room
body: <p>I downloaded the Room BasicSample app from here:
  <a href="https://github.com/googlesamples/android-architecture-components" rel="nofollow noreferrer">https://github.com/googlesamples/android-architecture-components</a></p>
  
  <p>This sample is a readonly database. There is no example to insert a single entity. I am modifying it, and struggling to figure out how to call the getDatabase so I can do a simple insert on the db on a button click -
   getDatabase().wordDao().insert(...) ?</p>
  
  <p>How do I get access to the singleton BasicApp and call getDatabase method, and where do I call it from?</p>
  
  <p>Any help is appreciated.</p>
  
  <p><strong>single Insert</strong></p>
  
  <pre><code>@Insert(onConflict = IGNORE)
  void insert(WordEntity word);
  </code></pre>
  
  <p><strong>AppDatabase.java</strong> (not sure if this insert method goes here)</p>
  
  <pre><code>private static void insert(final AppDatabase database, final WordEntity word) {
          database.wordDao().insert(word);
  }
  </code></pre>
  
  <p><strong>BasicApp.java</strong></p>
  
  <pre><code>public class BasicApp extends Application {
  
      private AppExecutors mAppExecutors;
  
      @Override
      public void onCreate() {
          super.onCreate();
  
          mAppExecutors = new AppExecutors();
      }
  
      public AppDatabase getDatabase() {
          return AppDatabase.getInstance(this, mAppExecutors);
      } // ==&gt; how do I get access to this?
  
      public DataRepository getRepository() {
          return DataRepository.getInstance(getDatabase());
      }
  }
  </code></pre>