0

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 this strategy

ProgressDialog pd = new ProgressDialog(mActivity);
pd.setTitle(mTitle);
pd.setMessage(mMessage);
pd.show();

to this:

ProgressDialog pd = ProgressDialog.show(mActivity,mTitle,mMessage);

for a particular situation?

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Luigi Blu
  • 129
  • 13

2 Answers2

2

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

public static ProgressDialog show(Context context, CharSequence title,
        CharSequence message) {
    return show(context, title, message, false);
}

public static ProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate) {
    return show(context, title, message, indeterminate, false, null);
}

public static ProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate, boolean cancelable) {
    return show(context, title, message, indeterminate, cancelable, null);
}

public static ProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate,
        boolean cancelable, OnCancelListener cancelListener) {
    ProgressDialog dialog = new ProgressDialog(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.

kurtacious
  • 445
  • 3
  • 7
1

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

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • Actually, the `show()` method is not static. It is an instance method in `Dialog`. – kurtacious Nov 22 '16 at 18:19
  • 2
    The doc says it is static – ΦXocę 웃 Пepeúpa ツ Nov 22 '16 at 18:21
  • Oh. @ΦXocę웃Пepeúpaツ: kurtacious is right. In [`Dialog`](https://developer.android.com/reference/android/app/Dialog.html) (a super type of [`ProgressDialog`](https://developer.android.com/reference/android/app/ProgressDialog.html)) there also exists a [`show`](https://developer.android.com/reference/android/app/Dialog.html#show()) method that is not static (and takes no arguments). OP asks for the difference between those two methods. – Seelenvirtuose Nov 22 '16 at 18:25
  • OP's question was about the difference between the two methods, not how you should call a static method. Regarding the `show()` method being non-static, See: https://developer.android.com/reference/android/app/Dialog.html#show() – kurtacious Nov 22 '16 at 18:45