title: How can i populate Room Persistence database in Android?
body: <p>I have an old database with the next structure:
  <a href="https://i.stack.imgur.com/KUxIZ.png" rel="nofollow noreferrer">Database structure</a></p>
  
  <p>The question is what is the best way to create and populate tables in Room Persistence Database. The way i do it now is a storing tables data in strings.xml and push it into database with firstrun.</p>
  
  <pre><code> public void createDb(final Context context) {
      mIsDatabaseCreated.setValue(false);
  
      prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
  
      boolean isFirstRun = prefs.getBoolean(prefKey, true);
      Observable.just(Room.databaseBuilder(context.getApplicationContext(),
              AppDatabase.class, AppDatabase.DATABASE_NAME).build())
              .map(appDatabase1 -&gt; DatabaseInitUtil.initializeDb(
                      appDatabase1, 
                      context.getResources().getStringArray(R.array.themes),
                      isFirstRun))
              .subscribeOn(Schedulers.io())
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe(appDatabase -&gt; {
                  mDb = appDatabase;
                  mIsDatabaseCreated.setValue(true);
              });
  
      prefs.edit().putBoolean(prefKey, false).apply();
  }
  
   static AppDatabase initializeDb(AppDatabase appDatabase, String[] themes, boolean isFirstRun) {
  
      if (isFirstRun) {
          List&lt;ThemeEntity&gt; themesEntities = new ArrayList&lt;&gt;(themes.length);
          generateData(themesEntities, themes);
          return insertData(appDatabase, themesEntities);
      } else {
          return appDatabase;
      }
  
  }
  
  private static void generateData(List&lt;ThemeEntity&gt; themesEntities, String[] themes) {
      for (String theme : themes) {
          ThemeEntity themeEntity = new ThemeEntity();
          themeEntity.setTheme(theme);
          themesEntities.add(themeEntity);
      }
  }
  
  
  &lt;string-array name="themes"&gt;
      &lt;item&gt;@string/courage&lt;/item&gt;
      &lt;item&gt;@string/death&lt;/item&gt;
      &lt;item&gt;@string/forgiveness&lt;/item&gt;
      &lt;item&gt;@string/faith&lt;/item&gt;
      &lt;item&gt;@string/family&lt;/item&gt;
      &lt;item&gt;@string/encouragement&lt;/item&gt;
      &lt;item&gt;@string/friendship&lt;/item&gt;
      &lt;item&gt;@string/joy&lt;/item&gt;
      &lt;item&gt;@string/life&lt;/item&gt;
      &lt;item&gt;@string/love&lt;/item&gt;
      &lt;item&gt;@string/relationship&lt;/item&gt;
      &lt;item&gt;@string/strength&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>
  
  <p>But i think that storing a large data in strings arrays and get it with first run it is not right  way.</p>