title: AlertDialog.Builder show(), crash in click handler
body: <p>My app opens a new view from the main view with:</p>
  
  <pre><code>Intent ElementsIntent = new Intent(this, ElementList.class);
  startActivityForResult(ElementsIntent, 0);
  </code></pre>
  
  <p>which shows a list of elements and when pushing 1 of these elements a view opens up the same way as before with a new Activity. Inside this view I would like to show a  AlertDialog in a button click handler, but when I call show() the app crashes. </p>
  
  <p>I am pretty sure it has got somthing to do with the Context not being correct according to where I try and open the dialog, but I have tried making a static context from the main view, I have tried with element.this, which is the class connected to the activity, and I have tried getApplicationContext, and all of these result in an app crash.</p>
  
  <p>I hope someone can explain what I am doing wrong.</p>
  
  <p>Thanks.</p>
  
  <p>Here is the AlertDialog code which crashes:</p>
  
  <pre><code>public void GoBackClickHandler(View v)
  {
      AlertDialog.Builder builder = new AlertDialog.Builder(ElementItem.this);
      builder.setMessage("Skal ændringer i besvarelse gemmes?")
             .setCancelable(false)
             .setPositiveButton("Ja", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     dialog.cancel();
                  if(inputIsValue())
                  {
                      UpdateELement task = new UpdateELement();
                      task.applicationContext = ElementItem.this;
                      task.execute(1);
                  }
                 }
             })
             .setNegativeButton("Nej", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                      dialog.cancel();
                      finish();
                 }
             });
      AlertDialog alert = builder.create();
      alert.show();       
  }
  </code></pre>
  
  <p>If I move this code to the OnCreate, then the alert shows just fine and no app crash. It is only if I place it in a ClickHandler it crashes.</p>