title: how to display progress dialog while installing sqllite database in android?
body: <p>I am trying to display a progress dialog when the app runs for the first time since it installs database and takes a while to do that because of the DB size.  Here is the ListAcitity that I am using:
      package samples.employeedirectory;</p>
  
  <pre><code>import android.app.ListActivity;
  import android.content.Intent;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.WindowManager;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  
  public class EmployeeList extends ListActivity {
  
  protected SQLiteDatabase db;
  protected Cursor cursor;
  protected ListAdapter adapter;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      new progressBar().execute();
      db = (new DatabaseHelper(this)).getWritableDatabase();
      cursor = db.rawQuery("SELECT * FROM employeeList", new String[]{});
  
      adapter = new qCursorAdapter(this, cursor);
  
      // requestWindowFeature(Window.FEATURE_NO_TITLE);
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                               WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
      setListAdapter(adapter);
  
  }
  
  public void onListItemClick(ListView parent, View view, int position, long id) {
      Intent intent = new Intent(this, displayEmployee.class);
      Cursor cursor = (Cursor) adapter.getItem(position);
      intent.putExtra("eID", cursor.getInt(cursor.getColumnIndex("eID")));
      startActivity(intent);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menu, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.pref:
              // Launch Preference activity
              Intent intent = new Intent(this, Preferences.class);
              startActivity(intent);
           break;
      }
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I realized then that I can't display progress bar before the activity starts. What is the best approach to achieve this?</p>
  
  <p>Edit:
  Using this code:</p>
  
  <pre><code>package samples.employeedirectory;
  
  import android.app.ProgressDialog;
  import android.content.Context;
  import android.database.sqlite.SQLiteDatabase;
  import android.os.AsyncTask;
  
  public class progressBar extends AsyncTask&lt;String, Void, String&gt; {
  protected Context context;
  protected SQLiteDatabase db;
  protected ProgressDialog dialog;
  @Override
  protected String doInBackground(String... params) {
      db = (new DatabaseHelper(context)).getWritableDatabase();
      return null;
  }
  
  /* (non-Javadoc)
   * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
   */
  @Override
  protected void onPostExecute(String result) {
      // TODO Auto-generated method stub
      super.onPostExecute(result);
      dialog.dismiss();
  }
  
  /* (non-Javadoc)
   * @see android.os.AsyncTask#onPreExecute()
   */
  @Override
  protected void onPreExecute() {
      // super.onPreExecute();
  dialog = ProgressDialog.show(context, "",
              "Please wait for few seconds...", true);
  }
  
  /* (non-Javadoc)
   * @see android.os.AsyncTask#onProgressUpdate(Progress[])
   */
  @Override
  protected void onProgressUpdate(Void... values) {
      // TODO Auto-generated method stub
      super.onProgressUpdate(values);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I received these errors:</p>
  
  <pre><code>    08-15 23:21:26.743: ERROR/AndroidRuntime(5170): java.lang.RuntimeException: Unable to start activity ComponentInfo{samples.employeedirectory/samples.employeedirectory.EmployeeList}: java.lang.NullPointerException
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ActivityThread.access$1500(ActivityThread.java:121)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.os.Handler.dispatchMessage(Handler.java:99)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.os.Looper.loop(Looper.java:123)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ActivityThread.main(ActivityThread.java:3701)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at java.lang.reflect.Method.invokeNative(Native Method)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at java.lang.reflect.Method.invoke(Method.java:507)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at dalvik.system.NativeStart.main(Native Method)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170): Caused by: java.lang.NullPointerException
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.Dialog.&lt;init&gt;(Dialog.java:141)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.AlertDialog.&lt;init&gt;(AlertDialog.java:67)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ProgressDialog.&lt;init&gt;(ProgressDialog.java:80)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ProgressDialog.&lt;init&gt;(ProgressDialog.java:76)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ProgressDialog.show(ProgressDialog.java:101)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ProgressDialog.show(ProgressDialog.java:90)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at samples.employeedirectory.progressBar.onPreExecute(progressBar.java:34)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.os.AsyncTask.execute(AsyncTask.java:391)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at samples.employeedirectory.EmployeeList.onCreate(EmployeeList.java:27)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
      08-15 23:21:26.743: ERROR/AndroidRuntime(5170):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
  </code></pre>