title: Stopping an Activity in Android
body: <p>I had read about this thread around the Internet but unlucky to find a solution. The solutions that are available did not work for me like adding the <code>android:noHistory="true"</code> in the Manifest file. What I wanted is that after the user clicks the play game button, which will redirect the user into the select difficulty page, when the user clicks the back button (android emulator), it will go back to the main menu.</p>
  
  <p>This is my manifest file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kfc"
    android:versionCode="1"
    android:versionName="1.0"&gt;
  &lt;uses-sdk android:minSdkVersion="10" /&gt;
  
  &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
      &lt;activity android:name=".NewKFCActivity"
                android:label="@string/app_name"
                android:noHistory="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;activity android:name=".HelpPageOne"
                android:label="@string/app_name"
                android:noHistory="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.kfc.HELPPAGEONE" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;activity android:name=".HelpPageTwo"
                android:label="@string/app_name"
                android:noHistory="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.kfc.HELPPAGETWO" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;activity android:name=".SelectDifficulty"
                android:label="@string/app_name"
                android:noHistory="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.kfc.SELECTDIFFICULTY" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is my main activity:</p>
  
  <pre><code>package com.kfc;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.Window;
  import android.widget.ImageButton;
  
  public class NewKFCActivity extends Activity {
      /** Called when the activity is first created. */
      ImageButton bPlay, bHelp;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          this.requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.main);
          bPlay = (ImageButton) findViewById(R.id.playGame);
          bPlay.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(v.getContext(), SelectDifficulty.class);
                  startActivityForResult(intent,0);
                  finish();
              }
          });
  
          bHelp = (ImageButton) findViewById(R.id.Help);
          bHelp.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(v.getContext(), HelpPageOne.class);
                  startActivityForResult(intent,0);
                  finish();
              }
          });
  
  
      }
      @Override
      protected void onPause() {
          // TODO Auto-generated method stub
          super.onPause();
          finish();
      }
  }
  </code></pre>
  
  <p>This is my difficulty class:</p>
  
  <pre><code>package com.kfc;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ImageButton;
  
  public class SelectDifficulty extends Activity{
      ImageButton bEasy, bMedium, bHard;
      @Override
      protected void onCreate(Bundle kfcState) {
          // TODO Auto-generated method stub
          super.onCreate(kfcState);
          setContentView(R.layout.difficultyxml);
  
          bEasy = (ImageButton) findViewById(R.id.easy);
          bEasy.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  //Intent intent = new Intent(v.getContext(), NewKFCActivity.class);
                  //startActivityForResult(intent,0);
              }
          });
      }
  
  }
  </code></pre>