title: Killing one activity from another
body: <p>I have two activities A and B. B is a transparent pass through activity, and A is seen. I want to kill B by pressing a button A.</p>
  
  <p>Here's what I've tried so far:</p>
  
  <pre><code>B obj=new B();
  obj.finish();
  </code></pre>
  
  <p>I created an object of B and tried to kill it. That didn't work.</p>
  
  <pre><code>intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  intent.putExtra("keep", true);
                  startActivity(intent);
  </code></pre>
  
  <p>What this code is supposed to do is clear the top most activity, which is B and call B again, except this time I'm passing a value such that B kills itself after a few seconds.</p>
  
  <p>This only piled up more instances of the activity for some reason. Or at least I think that's what happened because the screen became pixelated due to many transparent activities.</p>
  
  <p>Here's my manifest:</p>
  
  <pre><code>&lt;activity
          android:name="com.xxx.xxx.B"
          android:excludeFromRecents="true"
          android:theme="@android:style/Theme.Translucent.NoTitleBar"
          android:clearTaskOnLaunch="true" &gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>What do I have to do so that, when I hit a button once the activity is displayed and the second time kills it? The creation part is obviously taken care of. My activity B pops up, I want to kill it now that B is on top.</p>
  
  <p><b>EDIT</b></p>
  
  <p>I tried this with a checkBox, here's the code:</p>
  
  <pre><code>enable.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
              finishActivity(0);
              Intent intent = new Intent(A.this, B.class);
              if (enable.isChecked()) {
                  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  intent.putExtra("keep", true);
                  intent.putExtra("value", 10);
                  startActivityForResult(intent, 0);
              }
              else
              {
                  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  intent.putExtra("keep", false);
                  startActivityForResult(intent, 0);
              }
          }
      });
  </code></pre>
  
  <p>When enable is checked the activity is called, which works fine. But they keep piling on. It's not like this A->B->A->B when I check and uncheck the checkBox. It's A->B->BB->BBB</p>