title: Android: write a class for using alert dialog every where
body: <p>I am new in android and I have tried to write a class <code>MyAlertDialog</code> for alert dialog to use it every where I need an alert dialog. I have written a method <code>showAlertDialog</code> in the class to do this. I found that the method have to be static. Could anybody tell me why it should be static? Here is my code:</p>
  
  <pre><code>public class MyAlertDialog extends AppCompatActivity {
  
  public static void alertDialogShow(Context context, String message) {
  
      final Dialog dialog;
      TextView txtAlertMsg;
      TextView txtAlertOk;
  
      dialog = new Dialog(context);
      dialog.setContentView(R.layout.activity_my_alert_dialog);
      txtAlertOk = (TextView) dialog.findViewById(R.id.txtAalertOk);
      txtAlertMsg = (TextView) dialog.findViewById(R.id.txtAlertMsg);
      txtAlertMsg.setText(message);
      txtAlertOk.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              dialog.dismiss();
          }
      });
      dialog.show();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and I have called it like bellow:</p>
  
  <pre><code>MyAlertDialog.alertDialogShow(MainActivity.this,"Here is my message");
  </code></pre>