title: finish activity from custom view using context
body: <p>Here's my code:</p>
  
  <pre><code>    private void makeDialog2() {
      AlertDialog.Builder about = new AlertDialog.Builder(getContext());
      about.setTitle("You Won!");
  
      about.setPositiveButton("Play Again",
              new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface arg0, int arg1) {
                      Intent playIntent2 = new Intent(getContext(),
                              PracticePlayActivity.class);
                      playIntent2.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                      getContext().startActivity(playIntent2);
                      ((Activity) getContext()).finish();
                  }
              });
  
      about.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface arg1, int arg2) {
              Intent playIntent = new Intent(getContext(),
                      PlayChooserActivity.class);
              playIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
              getContext().startActivity(playIntent);
              ((Activity) getContext()).finish();
          }
      });
  
      about.show();
  }
  </code></pre>
  
  <p>This code is prompted when the user loses the game and wants to retry. However when i press retry more than 4 times the application crashes. I'm suspecting a memory leak. After some testing in logcat i managed to find out that the activity is still running after retrying.</p>
  
  <p>My plan is to attack this problem with two things. Recycling my drawables and ending the first activity as a whole. However, the first activity is not closing even after i call finish. Any help? (Using getContext() in other parts of my code has worked so far).</p>
  
  <p>EDIT: By ending the activity does it destroy the variables automatically? or do i still need to clear the bitmaps from the Android memory? Any ideas how i can do this?</p>