title: Store value in SharedPreference and get From it in android
body: <p>i am new to android and i have been using this code to save the value of my Checkboxes
  when the app closes which works fine (in Settings.class)</p>
  
  <pre><code>        public void putBooleanInPreferences(boolean isChecked,String key){
          SharedPreferences sharedPreferences =     this.getPreferences(Activity.MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPreferences.edit();
          editor.putBoolean(key, isChecked);
          editor.commit();        
          }
          public boolean getBooleanFromPreferences(String key){
          SharedPreferences sharedPreferences = this.getPreferences(Activity.MODE_PRIVATE);
          Boolean isChecked = sharedPreferences.getBoolean(key, false);
          return isChecked;       
  
          }
  </code></pre>
  
  <p>but i want to use the same saved value in another activity  (Progress.class)</p>
  
  <p>here are my activities</p>
  
  <p><strong>Settings.class</strong></p>
  
  <pre><code>          checkBox_one = (CheckBox) findViewById(R.id.checkBox1);
  
            boolean isChecked = getBooleanFromPreferences("isChecked");
            Log.i("start",""+isChecked);
            checkBox_one.setChecked(isChecked);
            //checkBox_one.setChecked(true);//Enable By Default
            checkBox_one.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
              @Override
              public void onCheckedChanged(CompoundButton view, boolean isChecked) {
                  Log.i("boolean",""+isChecked);
                  Settings.this.putBooleanInPreferences(isChecked,"isChecked");
              }
            });
  
            checkBox_two = (CheckBox) findViewById(R.id.checkBox2);
  
            boolean isCheckedTwo = getBooleanFromPreferences("isCheckedTwo");
            checkBox_two.setChecked(isCheckedTwo );
            //checkBox_two.setChecked(true);//Enable By Default
            checkBox_two.setOnCheckedChangeListener(new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton view, boolean isChecked) {
  
                  Settings.this.putBooleanInPreferences(isChecked,"isCheckedTwo");
              }
            });
  
            checkBox_three = (CheckBox) findViewById(R.id.checkBox3);
  
            boolean isCheckedThree = getBooleanFromPreferences("isCheckedThree");
            checkBox_three.setChecked(isCheckedThree );
            checkBox_three.setOnCheckedChangeListener(new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton view, boolean isChecked) {
  
                  Settings.this.putBooleanInPreferences(isChecked,"isCheckedThree");
              }
            });
  
            checkBox_four = (CheckBox) findViewById(R.id.checkBox4);
  
            boolean isCheckedFour = getBooleanFromPreferences("isCheckedFour");
            checkBox_four.setChecked(isCheckedFour );
            //checkBox_four.setChecked(true);//Enable By Default
            checkBox_four.setOnCheckedChangeListener(new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton view, boolean isChecked) {
  
                  Settings.this.putBooleanInPreferences(isChecked,"isCheckedFour");
              }
            });
  
            checkBox_five = (CheckBox) findViewById(R.id.checkBox5);
  
            boolean isCheckedFive = getBooleanFromPreferences("isCheckedFive");
            checkBox_five.setChecked(isCheckedFive );
            checkBox_five.setOnCheckedChangeListener(new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton view, boolean isChecked) {
  
                  Settings.this.putBooleanInPreferences(isChecked,"isCheckedFive");
              }
            });
  
          }
  
          public void putBooleanInPreferences(boolean isChecked,String key){
          SharedPreferences sharedPreferences = this.getPreferences(Activity.MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPreferences.edit();
          editor.putBoolean(key, isChecked);
          editor.commit();        
          }
          public boolean getBooleanFromPreferences(String key){
          SharedPreferences sharedPreferences = this.getPreferences(Activity.MODE_PRIVATE);
          Boolean isChecked = sharedPreferences.getBoolean(key, false);
          return isChecked;       
  
          }
          //-------------------------//
  </code></pre>
  
  <p>and here is <strong>Progress.Class</strong></p>
  
  <pre><code>        progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
          progressBar2 = (ProgressBar) findViewById(R.id.progressBar2);
          checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
          checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
  
          checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  updateProgressBars();
              }
          });
  
          checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  updateProgressBars();
              }
          });
          }
  
          public void updateProgressBars() {
  
            progressBar1.setVisibility(View.GONE);
            progressBar2.setVisibility(View.GONE);
  
           if (checkBox1.isChecked() &amp;&amp; checkBox2.isChecked()) {
              progressBar2.setVisibility(View.VISIBLE);
           } else if (checkBox1.isChecked()) {
              progressBar1.setVisibility(View.VISIBLE);
           }
  </code></pre>