Progress Dialog on open activity

I had the same issue and using an AsyncTask is working for me.

There are 3 important methods to override in AsyncTask.

  1. doInBackground : this is where the meat of your background processing will occur.
  2. onPreExecute : show your ProgressDialog here ( showDialog )
  3. onPostExecute : hide your ProgressDialog here ( removeDialog or dismissDialog )

If you make your AsyncTask subclass as an inner class of your activity, then you can call the framework methods showDialog, dismissDialog, and removeDialog from within your AsyncActivity.

Here's a sample implementation of AsyncTask:

class LoginProgressTask extends AsyncTask<String, Integer, Boolean> {
  @Override
  protected Boolean doInBackground(String... params) {
    try {
      Thread.sleep(4000);  // Do your real work here
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    return Boolean.TRUE;   // Return your real result here
  }
  @Override
  protected void onPreExecute() {
    showDialog(AUTHORIZING_DIALOG);
  }
  @Override
  protected void onPostExecute(Boolean result) {
    // result is the value returned from doInBackground
    removeDialog(AUTHORIZING_DIALOG);
    Intent i = new Intent(HelloAndroid.this, LandingActivity.class);
    startActivity(i);
  }
}

AFAIK you cannot preload any activity with progress dialog displayed. Are you testing on a real device or in emulator?

I've seen workarounds that opened an activity with a ViewFlipper having a progress animation in the center, and in the next View, it was loaded an activity, but it's not something is recommended and hard to implement to work as you wish.


GeeXor

I would suggest you to avoid performing lots of operations in Activity 2's OnCreate.Writing lots of operations in OnCreate is a reason for the black screen between activities.So perform those operations asynchronously using AsyncTask or in a Thread (or write them in onStart if they are unavoidable).

The other suggestion is to start another progressDialog in activity 2's onCreate which will run until all of your data is loaded & user will know that something is happening in background.