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:
- define
Progress Bar
element in xml file - set visibility to
GONE
orVISIBLE
for theProgress Bar
element in java file.
Here are some references for Progress Bar
:
- Official documentation: https://developer.android.com/reference/android/widget/ProgressBar
- Example: https://abhiandroid.com/ui/progressbar
- 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
How to Set a Particular Font for a Button Text in Android
Get List of Photo Galleries on Android
Java.Lang.Outofmemoryerror: Bitmap Size Exceeds Vm Budget
Lazy Download Images into Gridview
Firebase Overwrites Signin with Google Account
What Does the Layoutinflater Attachtoroot Parameter Mean
Android: Share Plain Text Using Intent (To All Messaging Apps)
Programmatically Getting the Gateway and Subnet Mask Details
Check If Correct Google Play Service Available: "Unfortunately Application Has Stopped Working"
Add a Header to a Gridview (Android)
How to Run Code on a Background Thread on Android
How to Use Setarguments() and Getarguments() Methods in Fragments
How to Crop an Image in Android
Adding an Onclicklistener to Listview (Android)
Add Shadow to Custom Shape on Android