progress dialog in main activity's onCreate not shown

custom progress dialog in android
progress dialog in activity
how to show progress dialogue in android
progress dialog in android programmatically
progress dialog with percentage in android
android progress dialog spinner
android show progress dialog for 5 seconds
android progress bar vs progress dialog

After the splash screen, it takes about 6 sec to load onCreate contents in the Main activity. So I want to show a progress dialog while loading and here's what I did:

import ...

private ProgressDialog mainProgress;

public void onCreate(Bundle davedInstanceState){


    mProgress = new ProgressDialog (Main.this);
    mProgress.setMessage("Loading... please wait");

    ---some code---


    ---some code---


and it doesn't work... the screen stays black for 5-6 sec and then load the main layout. I dont know which part I did wrong :*(

You need to do start your busy code in an other thread (than the UI thread). In your activity create the ProgressDialog and close it in the thread

mProgress = new ProgressDialog (Main.this);

Runnable runnable = new Runnable() {
    public void run() {
        // code that needs 6 seconds for execution

        // after finishing, close the progress bar

new Thread(runnable).start();

How to show ProgressDialog across launching a new Activity , onCreate(savedInstanceState); this.pd =, the result data back to the main activity = result;  This example demonstrates how do I to display progress dialog before starting an activity in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

It's because you're doing everything on the UI thread, thus blocking it.

You should do all your heavy-lifting in a separate thread and update the progress dialog through that

ProgressDialog, The file is given below. package com.​journaldev.progressdialog; import android. Step 1: Create a new project and name it ProgressDialogExample. Step 2: Open res -> layout -> activity_main. xml (or) main. xml and add following code: Here define two buttons <?xml Step 3 : Now open app -> java -> package -> MainActivity. java and add the below code.

I changed debuggable flag to true in AndroidManifest.xml.


Android ProgressDialog Example, Android Progress Dialog is a UI which shows the progress of a task like you want Step 3 : Now open app -> java -> package -> and add the  A Progress Dialog is a dialog with a progress indicator and text message. Progress Dialog is useful while you’re doing some task on your app that needs time to complete, like getting data from a server, because you don’t want to leave your users staring at their screens without letting them know that something is happening in the background.

ProgressDialog Tutorial With Example In Android Studio, onCreate(savedInstanceState); setContentView(R.layout.main); activity = this; progDailog =, "Loading","Please wait", true);  So, let’s say I must accomplish several tasks before giving the user the ability to use the main activity. At each step I advance a little. When I’m finished loading, I set to 100 and it closes, finally allowing me to use the app. java code examples, onCreate(savedInstanceState); setContentView(R.layout.main); activity = this; progDailog =, "Loading","Please wait", true);  It is usually safe to proxy this call to the owner activity's OnCreateOptionsMenu(IMenu) if the client desires the same menu for this Dialog. (Inherited from Dialog) OnCreatePanelMenu(Int32, IMenu) OnCreatePanelMenu(Int32, IMenu) Initialize the contents of the menu for panel 'featureId'. (Inherited from Dialog) java code examples, Add following snippet to MainActivity private ProgressDialog mDialog; @Override protected void onCreate(Bundle savedInstanceState) { super. I personally would not use a progress dialog in this case, but rather have a progress indicator on each of the grid items while the images are loading. But if you really want a progress dialog, you have to, as I mentioned before, implement some logic in your Adapter which tells you when an Item is loaded.