title: Stop activity when recent button or back button is pressed?
body: <p>In my app when I pressed the back button or the recents button (shows apps) and I go back into the app the value that is the users score begins doubling the original value. </p>
  
  <p>I believe it has something to do with onResume running in the background and when they re-enter the app it runs twice. I have tried:</p>
  
  <pre><code>public void onStop(){
      super.onStop()
      finish();
  }
  </code></pre>
  
  <p>But that ends the activity and when the user enters the second app the user goes to the second activity instead of the main one.</p>
  
  <p>Here is the code for that activity:</p>
  
  <pre><code>package com.example.navjeevenmann.mytycoon;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.Handler;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  
  public class MainActivity extends AppCompatActivity {
      private Button myButton;
      private int Counter;
      private Button myButton2;
      private TextView myTextView;
      Handler handler = new Handler();
      private int add;
      private TextView myAddView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          setContentView(R.layout.activity_main);
          super.onCreate(savedInstanceState);
          Bundle bundle = getIntent().getExtras();
          if (bundle != null) {
              if (bundle.containsKey("Count")) {
                  Counter = bundle.getInt("Count");
              }
              if (bundle.containsKey("Add")) {
                  add = bundle.getInt("Add");
              }
          }
  
          myButton = (Button) findViewById(R.id.button);
          myButton2 = (Button) findViewById(R.id.button2);
          myTextView = (TextView) findViewById(R.id.textView);
          myAddView = (TextView) findViewById(R.id.textView2);
          myButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Counter = ButtonCounter(Counter);
              }
          });
          myButton2.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent(getApplicationContext(),                 SecondActivity.class);
                  intent.putExtra("Count", Counter);
                  intent.putExtra("Add", add);
                  startActivity(intent);
              }
  
          });
  
      }
  
      public void onResume() {
          super.onResume();
          handler.postDelayed(new Runnable() {
              @Override
              public void run() {
                  Counter = AutoCounter(Counter, add);
                  handler.postDelayed(this, 1000);
              }
          }, 1000);
  
          handler.postDelayed(new Runnable() {
              @Override
              public void run() {
                  Display(Counter, add);
                  handler.postDelayed(this, 1);
              }
          }, 50);
      }
  
  
  
      public int ButtonCounter(int Counter) {
          Counter += 1;
          return Counter;
      }
  
      public int AutoCounter(int Counter, int add) {
          Counter = Counter + add;
          return Counter;
      }
  
      public void Display(int Counter, int add) {
          String money = String.valueOf(Counter);
          myTextView.setText("$" + money);
          myAddView.setText("Generating $" + add + "/Per Second");
  
      }
  
  }
  </code></pre>