Displaying a Progress Dialog in Android

Please wait Dialog is a common feature of the android devices. Demo :
screenshot_2017-01-10-14-18-08

Example

package pginicu.org.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.ProgressDialog;
import android.os.CountDownTimer;

public class MainActivity extends AppCompatActivity {

    ProgressDialog progressDialog;

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

    // When activity starts onStart method is fired automatically
    public void onStart()
    {
        super.onStart();
        // progress dialog Label
        progressDialog = ProgressDialog.show(this,"Please wait", "processing.....", true);

        // displaying Progress Dialog
        new CountDownTimer(5000,1000) { // countdown for 5 seconds
            @Override
            public void onTick(long l) {

            }

            @Override
            public void onFinish() {
                progressDialog.dismiss();

            }
        }.start();
    }

}
Share

You may also like...