title: passing this to an outer class and starting an activity from alertdialog's list on Android
body: <p>I am developing an Android app, this app has a dozen of Activities, each one is for a corresponding screen. Now I have this common subtitle bar on top of the screens.
  this subtitle bar has a button to display an alert dialog which shows link list to go to a different screen.</p>
  
  <p>I could write a same function for each activity to call the alert dialog, but that would be tedious if I want to modify them, so I created this class:</p>
  
  <pre><code>public class MenuAlertDialog extends Activity {
  
  /*
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
  }
   */
  public void createMenu(final Context context){
      AlertDialog.Builder dlg = new AlertDialog.Builder(context);
      dlg.setTitle("menu");
  
      String[] items = {"pageA", "pageB", "pageC", "pageD", "pageE"};
      dlg.setItems(items, new DialogInterface.OnClickListener(){
          @Override
          public void onClick(DialogInterface dialog, int which){
              switch(which){
              case 0:
                  Intent intent = new Intent(context, MainActivity.class);
                  startActivity(intent);
                  break;
              default:
                  break;
  
              }
          }
      });
      dlg.show();
  }
  }
  </code></pre>
  
  <p>and call it from each activity, like this:</p>
  
  <pre><code>MenuAlertDialog menu = new MenuAlertDialog();
  menu.createMenu(this);
  </code></pre>
  
  <p>from inside of onCreate.</p>
  
  <p>It can display the alertDialog, but whenever I press pageA link, it fails with an unexpected error.</p>
  
  <p>Logcat says its a nullpointererror and the cause seems</p>
  
  <pre><code>startActivity(intent);
  </code></pre>
  
  <p>What am I doing wrong?</p>