title: Progress Dialog when Creating database for the first time
body: <p>I have an app that creates a SQLite database ( with 24 records ), I am noticing that when I load the app for the first time it takes it a few to actually load the main view, and I assume it is because the app is creating the database for the first time. Here is what it's doing.
  1.) Shows Splash Screen
  2.) Blank screen - not programmed in or in any layout, this is where it's creating the database, again I assume
  3.) Shows Main layout - goal</p>
  
  <p>I would love to figure out the best way to display a progress bar during the blank screen, if possible maybe by counting the inserts of the database, not really sure here.</p>
  
  <p>Here is my code</p>
  
  <p>SplashActivity.java</p>
  
  <pre><code>package com.ondrovic.boombozzpassport;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Message;
  
  public class SplashActivity extends Activity{
  @Override
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      SplashHandler sHandler = new SplashHandler();
      setContentView(R.layout.splash);
  
      Message msg = new Message();
      msg.what = 0;
      sHandler.sendMessageDelayed(msg, 3000);
  
  }
  
  private class SplashHandler extends Handler {
      @Override
      public void handleMessage(Message msg) {
          switch (msg.what) {
          default:
              break;
          case 0:
              super.handleMessage(msg);
  
              startActivity(new Intent(getApplicationContext(), MainActivity.class));
              SplashActivity.this.finish();
          }
      }
  }
   }
  </code></pre>
  
  <p>Database.java</p>
  
  <pre><code> package com.ondrovic.boombozzpassport;
  
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
  
   import android.content.ContentValues;
   import android.content.Context;
   import android.database.sqlite.SQLiteDatabase;
   import android.database.sqlite.SQLiteOpenHelper;
   import android.graphics.Bitmap;
   import android.graphics.BitmapFactory;
   import android.provider.BaseColumns;
   import android.util.Log;
  
   public class Database extends SQLiteOpenHelper implements BaseColumns {
  private final static String DB_NAME = "boombozz.db";
  private final static int DB_VERSION = 1;
  static final String TABLE_BEERS = "beers";
  static final String COL_NAME = "name";
  static final String COL_BREWER = "brewer";
  static final String COL_ABV = "abv";
  static final String COL_RATE = "rating";
  static final String COL_BDESC = "breifdescription";
  static final String COL_FDESC = "fulldescription";
  static final String COL_TYPE = "type";
  static final String COL_PIC = "picture";
  
  private Context mContext;
  
  public Database(Context context) {
      super(context, DB_NAME, null, DB_VERSION);
      mContext = context;
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      Log.w("onCreate : ","Creating Database Version: " + DB_VERSION);
      db.execSQL("CREATE TABLE beers (" + "_id INTEGER PRIMARY KEY, "
              + "name TEXT, " + "brewer TEXT, " + "abv REAL, "
              + "rating REAL, " + "breifdescription TEXT, "
              + "fulldescription TEXT, " + "type TEXT, " + "picture BLOB);");
  
      Log.w("onCreate","Inserting records into database");
  
      addBeer(db, "NAME 1", "BREWER 1", "TYPE 1", "BDESC 1", "FDESC 1", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 2", "BREWER 2", "TYPE 2", "BDESC 2", "FDESC 2", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 3", "BREWER 3", "TYPE 3", "BDESC 3", "FDESC 3", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 4", "BREWER 4", "TYPE 4", "BDESC 4", "FDESC 4", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 5", "BREWER 5", "TYPE 5", "BDESC 5", "FDESC 5", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 6", "BREWER 6", "TYPE 6", "BDESC 6", "FDESC 6", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 7", "BREWER 7", "TYPE 7", "BDESC 7", "FDESC 7", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 8", "BREWER 8", "TYPE 8", "BDESC 8", "FDESC 8", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 9", "BREWER 9", "TYPE 9", "BDESC 9", "FDESC 9", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 10", "BREWER 10", "TYPE 10", "BDESC 10", "FDESC 10", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 11", "BREWER 11", "TYPE 11", "BDESC 11", "FDESC 11", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 12", "BREWER 12", "TYPE 12", "BDESC 12", "FDESC 12", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 13", "BREWER 13", "TYPE 13", "BDESC 13", "FDESC 13", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 14", "BREWER 14", "TYPE 14", "BDESC 14", "FDESC 14", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 15", "BREWER 15", "TYPE 15", "BDESC 15", "FDESC 15", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 16", "BREWER 16", "TYPE 16", "BDESC 16", "FDESC 16", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 17", "BREWER 17", "TYPE 17", "BDESC 17", "FDESC 17", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 18", "BREWER 18", "TYPE 18", "BDESC 18", "FDESC 18", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 19", "BREWER 19", "TYPE 19", "BDESC 19", "FDESC 19", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 20", "BREWER 20", "TYPE 20", "BDESC 20", "FDESC 20", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 21", "BREWER 21", "TYPE 21", "BDESC 21", "FDESC 21", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 22", "BREWER 22", "TYPE 22", "BDESC 22", "FDESC 22", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 23", "BREWER 23", "TYPE 23", "BDESC 23", "FDESC 23", 0, 0, R.drawable.beer1);
      addBeer(db, "NAME 24", "BREWER 24", "TYPE 24", "BDESC 24", "FDESC 24", 0, 0, R.drawable.beer1);
  
  }
  
  private void addBeer(SQLiteDatabase db, String name, String brewer,
          String type, String bdesc, String fdesc, int abv, int rate, int icon) {
      final ContentValues cv = new ContentValues();
      cv.put(COL_NAME, name);
      cv.put(COL_BREWER, brewer);
      cv.put(COL_TYPE, type);
      cv.put(COL_BDESC, bdesc);
      cv.put(COL_FDESC, fdesc);
      cv.put(COL_ABV, abv);
      cv.put(COL_RATE, rate);
  
      final Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), icon);
      writeBitmap(cv, COL_PIC, bitmap);
  
      db.insert(TABLE_BEERS, null, cv);
  }
  
  static void writeBitmap(ContentValues cv, String name, Bitmap bitmap) {
      if (bitmap != null) {
  
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          try {
              bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
              out.flush();
              out.close();
  
              cv.put(name, out.toByteArray());
          } catch (IOException e) {
              // Ignore
          }
      }
  
  }
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      Log.w("onUpgrade", "Upgrading database from version: " + oldVersion
              + " to version: " + newVersion);
      db.execSQL("DROP TABLE IF EXISTS beers");
  }
   }
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code> package com.ondrovic.boombozzpassport;
  
   import java.util.concurrent.atomic.AtomicBoolean;
  
   import com.pushlink.android.PushLink;
  
   import android.app.Activity;
   import android.content.Context;
   import android.content.Intent;
   import android.database.Cursor;
   import android.database.sqlite.SQLiteDatabase;
   import android.os.Bundle;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
   import android.widget.AdapterView;
   import android.widget.CursorAdapter;
   import android.widget.ListView;
   import android.widget.RatingBar;
   import android.widget.TextView;
  
   public class MainActivity extends Activity {
  
  AtomicBoolean isActive = new AtomicBoolean(true);
  
  BeerAdapter adapter = null;
  Cursor model = null;
  
  SQLiteDatabase db = null;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      PushLink.start(this, R.drawable.ic_launcher, 10, "269f78b325ebda1c", true);
  
      setContentView(R.layout.main);
  
      db = (new Database(this)).getWritableDatabase();
  
      ListView list = (ListView) findViewById(R.id.ListViewBeers);
  
      model = Beer.getAll(db);
      startManagingCursor(model);
      adapter = new BeerAdapter(model);
      list.setAdapter(adapter);
      list.setOnItemClickListener(onListClick);
  }
  
  private AdapterView.OnItemClickListener onListClick = new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View v, int pos, long id) {
          startActivity(new Intent(getApplicationContext(), BeerForm.class).putExtra(BeerForm.INTENT_BEER_ID, String.valueOf(id)));
      }
  };
  
  @Override
  public void onPause() {
      super.onPause();
      isActive.set(false);
  }
  
  @Override
  public void onResume() {
      super.onResume();
      isActive.set(true);
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
      isActive.set(false);
      db.close();
  }
  class BeerAdapter extends CursorAdapter {
  
      public BeerAdapter(Cursor c) {
          super(MainActivity.this, c);
      }
  
      @Override
      public void bindView(View row, Context ctxt, Cursor c) {
          BeerWrapper wrapper = (BeerWrapper)row.getTag();
          wrapper.populateFrom(c);
      }
  
      @Override
      public View newView(Context context, Cursor c, ViewGroup parent) {
          LayoutInflater inflater = getLayoutInflater();
          View row = inflater.inflate(R.layout.row, parent, false);
          BeerWrapper wrapper = new BeerWrapper(row);
  
          row.setTag(wrapper);
          wrapper.populateFrom(c);
  
          return row;
      }
  }
  
  class BeerWrapper {
  
      private TextView name = null;
      private TextView brewer = null;
      private TextView bdesc = null;
      private RatingBar rating = null;
      private View row = null;
  
      BeerWrapper(View row) {
          this.row = row;
      }
  
      void populateFrom(Cursor c) {
          getName().setText(c.getString(c.getColumnIndex("name")));
          getBrewer().setText(c.getString(c.getColumnIndex("brewer")));
          getDesc().setText(c.getString(c.getColumnIndex("breifdescription")));
          getRating().setRating(c.getFloat(c.getColumnIndex("rating")));
  
      }
  
      TextView getName() {
          if (name == null) {
              name = (TextView)row.findViewById(R.id.TextViewRowName);
          }
          return name;
      }
  
      TextView getBrewer() {
          if (brewer == null) {
              brewer = (TextView)row.findViewById(R.id.TextViewRowBrewer);
          }
          return brewer;
      }
  
      TextView getDesc() {
          if (bdesc == null) {
              bdesc = (TextView)row.findViewById(R.id.TextViewRowBriefDescription);
          }
          return bdesc;
      }
  
      RatingBar getRating() {
          if (rating == null) {
              rating = (RatingBar)row.findViewById(R.id.RatingBarRatingSmall);
          }
          return rating;
      }
  }
   }
  </code></pre>
  
  <p>Not sure the best place to put this or how to correctly implement to only show up when the database is created. Any ideas or suggestions?</p>