title: Save state button sharedpreferences Android
body: <p>i've got a floatingbutoon (it's a button shortly), and when i click on it it starts a service and the button change icon. I tried in this way:</p>
  
  <pre><code>mFab = (FloatingActionButton)findViewById(R.id.fabbutton);
  mFab.setDrawable(getResources().getDrawable(R.drawable.ic_play));
  mFab.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View view) {
                  if (RunService.isRunning) {
                      RunService.stopRun(MainActivity.this);
                      mFab.setDrawable(getResources().getDrawable(R.drawable.ic_play));
                      SharedPreferences.Editor editor = getSharedPreferences("com.mypck.asd", MODE_PRIVATE).edit();
                      editor.putBoolean("NameOfThingToSave", true);
                      editor.commit();
  
                  } else {
                      startService(new Intent(MainActivity.this, RunService.class));
                      mFab.setDrawable(getResources().getDrawable(R.drawable.ic_pause));
  
                  }
              }
          });
  </code></pre>
  
  <p>and to retrieve the state:</p>
  
  <pre><code>SharedPreferences sharedPrefs = getSharedPreferences("com.mypck.asd", MODE_PRIVATE);
  mFab.setChecked(sharedPrefs.getBoolean("NameOfThingToSave", true));
  </code></pre>
  
  <p>But not working in this way because <code>setChecked</code> method is for a toggle button..Instead mine is a simple button! How can i solve?</p>