When calling progressDialog = ProgressDialog.show(this, null, null, true);
usually the developers wants to only show the progress indication image, and usually
//create Dialog by using below method
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG1_KEY: {
Dialog dialog = new Dialog(this,R.style.NewDialog);
dialog.setContentView(R.layout.progress);
dialog.setCancelable(true);
return dialog;
}
}
return null;
}
//then in your onCreate () you can call like below
@Override
public void onCreate(Bundle savedInstatncestate)
{
final Handler mHandler = new Handler();
showDialog(DIALOG1_KEY);
new Thread() {
public void run() {
try {
sleep(3000);
Runnable r = new Runnable()
{
public void run()
{
//do your background process
dismissDialog(DIALOG1_KEY);
}
};
mHandler.post(r);
} catch (Exception e) {
}
}
}.start();
}
I use the following, it requires no layout file, and puts a centered, borderless blocking progress bar in the middle of the screen.
private ProgressDialog progressDialog;
setUIToWait(true);
...long process...
setUIToWait(false);
private void setUIToWait(boolean wait) {
if (wait) {
progressDialog=ProgressDialog.show(this,null,null);
progressDialog.setContentView(new ProgressBar(this));
} else {
progressDialog.dismiss();
}
}