title: How to make progress bar and load database running together in splash screen?
body: <p>I have splash screen which can load database sqlite before go to main activity. And my problem, progress bar layout run after loaded database. If we lauch app, app become blank layout (load database) -> progress bar running -> main activity. So, how to make progress bar and load database running together in splash screen?</p>
  
  <p>IntroActivity.java:</p>
  
  <pre><code>public class IntroActivity extends Activity implements LoadingTaskFinishedListener {
  private SQLiteDatabase db = null;
  private DataKamus datakamus = null;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      datakamus = new DataKamus(this);
      db = datakamus.getWritableDatabase();
      datakamus.createTable(db);
      datakamus.generateData(db);
  
      setContentView(R.layout.activity_intro);
  
      ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
       new Loading(progressBar, this).execute("");
  
  }
  
  @Override
  public void onTaskFinished() {
      completeSplash();
  }
  private void completeSplash(){
      startApp();
      finish(); // Don't forget to finish this Splash Activity so the user can't return to it!
  }
  private void startApp() {
      Intent intent = new Intent(IntroActivity.this, MainActivity.class);
      startActivity(intent);
  }
  </code></pre>
  
  <p>Loading.java:</p>
  
  <pre><code>public class Loading extends AsyncTask&lt;String, Integer, Integer&gt; {
  public interface LoadingTaskFinishedListener {
      void onTaskFinished();
  }
  
  private final ProgressBar progressBar;
  private final LoadingTaskFinishedListener finishedListener;
  
  public Loading(ProgressBar progressBar,
          LoadingTaskFinishedListener finishedListener) {
      this.progressBar = progressBar;
      this.finishedListener = finishedListener;
  }
  
  @Override
  protected Integer doInBackground(String... params) {
      Log.i("Tutorial", "Starting task with url: " + params[0]);
      if (resourcesDontAlreadyExist()) {
          downloadResources();
      }
      return 1234;
  
  }
  
  private boolean resourcesDontAlreadyExist() {
  
      return true;
  }
  
  private void downloadResources() {
  
      int count = 25;
      for (int i = 0; i &lt; count; i++) {
  
          int progress = (int) ((i / (float) count) * 100);
          publishProgress(progress);
  
          try {
              Thread.sleep(100);
          } catch (InterruptedException ignore) {
          }
      }
  }
  
  @Override
  protected void onProgressUpdate(Integer... values) {
      super.onProgressUpdate(values);
      progressBar.setProgress(values[0]);
  }
  
  @Override
  protected void onPostExecute(Integer result) {
      super.onPostExecute(result);
      finishedListener.onTaskFinished();
  }
  </code></pre>