I'm not sure there is any specific "correct way", but I find this
works well for me.

In the onCreate, check to see if you database exists. If it does
exists, just open it, if it doesn't exist, fire off and AsynTask that
pops up a progress dialog.  Here's the code I use:

@Override
protected void onCreate(Bundle savedInstanceState)
{
        super.onCreate(savedInstanceState);
        setContentView( R.layout.schedule );

        if( DBHelper.dbExists( this, DBHelper.DB_WHATEVER ) ==
DBHelper.STATUS_ALREADY_EXIST )
        {
                dbWhatever = DBHelper.dbOpen( this, DBHelper.DB_WHATEVER, false 
);
        }
        else openBackground( this );
}

private void openBackground( Context context )
{
        AsyncInit atInit = new AsyncInit();
        atInit.context = context;
        atInit.execute( null, null, null );
}

private class AsyncInit extends AsyncTask<Void, Void, Void>
{
        public Context context;
        private ProgressDialog pdDialog;

        @Override
        protected void onPreExecute()
        {
                bThreadRunning = true;
                pdDialog = ProgressDialog.show( context, "", "Creating database,
please wait...", true );
        }

        @Override
        protected void onPostExecute(Void result)
        {
                bThreadRunning = false;
                pdDialog.dismiss();
        }

        @Override
        protected Void doInBackground(Void... params)
        {
                dbWhatever = DBHelper.dbOpen( context, DBHelper.DB_WHATEVER, 
true );
                return null;
        }
}

The AsyncTask is built into Android and comes in really handy. Check
out the documentation at:

http://developer.android.com/reference/android/os/AsyncTask.html

It allows you to run a thread and use callbacks to update the UI
easily. Look at:

http://developer.android.com/reference/android/os/AsyncTask.html#onProgressUpdate%28Progress...%29

Super simple, pop dialog up, start your work, update dialog via the
above function, end work, end dialog.

Put whatever update function you want in the onPostExecute.

Note: the DBHelper class is something I've written to help me deal
with the database work. Just an FYI since it is used a lot in there.

Steven
Studio LFP
http://www.studio-lfp.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to