Progressdialog Is Deprecated.What Is the Alternate One to Use

Progress Dialog getting dismissed before displaying fetched data from firestore

The Progress Dialog dismissed instantly because you set Pd.dismiss() directly inside onCreate method.

Set Pd.dismiss() inside onSuccess so the Progress Dialog will be dismissed after finish fetching data from Firebase.

Progress Dialog is deprecated. You can use Progress Bar as its alternative. It's easy to use, all you have to do are:

  1. define Progress Bar element in xml file
  2. set visibility to GONE or VISIBLE for the Progress Bar element in java file.

Here are some references for Progress Bar:

  1. Official documentation: https://developer.android.com/reference/android/widget/ProgressBar
  2. Example: https://abhiandroid.com/ui/progressbar
  3. Another use in stackoverflow: ProgressDialog is deprecated.What is the alternate one to use?

Alternate of ProgressDialog

Why not adding a ProgressView to your Dialog view without creating a custom layout for Dialog

  LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setGravity(Gravity.CENTER);
ProgressBar progressBar = new ProgressBar(this);
LinearLayout.LayoutParams progressParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
progressParam.setMargins(0, 40, 0, 40);// set margin to progressBar
progressBar.setLayoutParams(progressParam);
linearLayout.addView(progressBar);

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Loading ")
.setMessage("Please waite until the map loaded")
.setView(linearLayout).setCancelable(false)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.create().show();

About Android Progress Dialog. Avoid?

Edit:
With Android O, ProgressDialog is now officially deprecated. An alternative is approach is suggested

This class was deprecated in API level O.
Use a progress indicator such as ProgressBar inline inside of an activity rather than using this modal dialog.


Original answer:

This is all from a design & user interaction perspective, not a code perspective.

The UI guidelines are telling you to avoid using a ProgressDialog not because the class is deprecated (it is not at the time of writing this answer), but rather because it forces the user to avoid interacting with the application and merely stare at the screen.

Take the Google Play app as an example. While it downloads an application/update, you can still swipe, navigate, etc. You can still be involved with the app while it is doing something.

If you absolutely need the user to cease interaction until the progress bar finishes, by all means do so. The docs are merely saying you may be able to find better ways of doing it (hence the link to Progress & Activity).



Related Topics



Leave a reply



Submit