title: Boolean and sharedpreference
body: <p>Hey i am trying to make my own app, i have already searched the web for info and i didn't understand the solutions other people found helpfull. but i have a little problem. I want the app to save the boolean value stopValue, when i close the app, but when i try this, it doesn't save the value when i close the app, instead it set the value to true.</p>
  
  <p>How do i fix this?</p>
  
  <p>Thanks for your help.</p>
  
  <pre><code>public class Main extends Activity{
  
  Button bStart, bStop;
  TextView tvDate, tvKm;
  Spinner spinner1;
  boolean stopValue;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      bStart = (Button) findViewById(R.id.bStart);
      tvDate = (TextView) findViewById(R.id.tvDate);
      tvKm = (TextView) findViewById(R.id.tvKm);
      spinner1 = (Spinner) findViewById(R.id.spinner1);
  
      boolean stopValue = false;
      SharedPreferences sp = getApplicationContext().getSharedPreferences("stopValue", 1);
      stopValue = sp.getBoolean("stop", false);
  
      stopValue = getIntent().getBooleanExtra("stop", stopValue);
  
      if(stopValue){
          bStart.setText("Start");
          bStart.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  Intent start = new Intent("com.uniqueapps.runner.START");
                  startActivity(start);
              }
          });
      }
      if(stopValue == false){
          bStart.setText("Stop");
          bStart.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent stop = new Intent("com.uniqueapps.runner.STOP");
                  startActivity(stop);
              }
          });
      }
  }
  
  @Override
  protected void onResume() {
      // TODO Auto-generated method stub
      super.onResume();
  }
  
  @Override
  protected void onPause() {
      // TODO Auto-generated method stub
      super.onPause();
  
      SharedPreferences sp = getApplicationContext().getSharedPreferences("stopValue", 1);
      Editor edit = sp.edit();
      edit.putBoolean("stop", true);
      edit.commit();
  }
  </code></pre>