Skip to content Skip to sidebar Skip to footer

Android - What Is Difference Between Progressdialog.show() And Progressdialog.show()?

I mean, what is difference between return value of ProgressDialog static method show() and the non-static method show of an instance of that class? Is there any reason to prefer th

Solution 1:

In my opinion, the "correct" method would depend on your usage. The static show( ... ) methods are performing the same steps you are:

publicstaticProgressDialogshow(Context context, CharSequence title,
        CharSequence message) {
    returnshow(context, title, message, false);
}

publicstaticProgressDialogshow(Context context, CharSequence title,
        CharSequence message, boolean indeterminate) {
    returnshow(context, title, message, indeterminate, false, null);
}

publicstaticProgressDialogshow(Context context, CharSequence title,
        CharSequence message, boolean indeterminate, boolean cancelable) {
    returnshow(context, title, message, indeterminate, cancelable, null);
}

publicstaticProgressDialogshow(Context context, CharSequence title,
        CharSequence message, boolean indeterminate,
        boolean cancelable, OnCancelListener cancelListener) {
    ProgressDialog dialog = newProgressDialog(context);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(cancelable);
    dialog.setOnCancelListener(cancelListener);
    dialog.show();
    return dialog;
}

You can see that any calls to the static show methods with parameters just ends up constructing a ProgressDialog and will call the instance method show().

Using the static show( ... ) methods just make it convenient for you to display a basic ProgressDialog using one line of code.

Solution 2:

writing it with capital p is the correct way to go since the method show is static

ProgressDialog.show(mActivity,mTitle,mMessage);

see the doc here

enter image description here

Is there any reason to prefer this strategy??

the reason why is the best way to go is that static methods should always be accessed in a static way

Post a Comment for "Android - What Is Difference Between Progressdialog.show() And Progressdialog.show()?"