title: How Save a int variable with SharedPreferences?
body: <p>Good day people,</p>
  
  <p>I have a problem I would save whith <code>SharedPreference</code>  simple int value variable,
  but I am having difficulty. 
  I have a Flag-Variable "signum" that changes the value based on the made choice <code>ImageButton</code>, I would save this Flag-Value.                                                It's possible in one <code>Activity</code> use twice method <code>SharedPreferences</code>?
  For me it's not important if the Flag-Value is a String or int variable, I need a easy way.
  I think(but I'm not sure even of this) I'm in the wrong store in the code-line I'm in the code line : salvum2.putInt("semper2", 1 or 2); insert the right way
  Thaks for all and for your help!</p>
  
  <pre><code>public class MainActivity extends Activity {
  private static final String MUTATIO = "semper";
  private static final String MUTATIO2 = "semper2";
  private ImageButton button;
  int signum ;  //this is the variable that I want to save
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      choicheimagebutton();
      operation();
  }
  
  
  private void choicheimagebutton() {
      final SharedPreferences optio =         
              getSharedPreferences(MUTATIO, Context.MODE_PRIVATE);
  
      final SharedPreferences optio2 = 
              getSharedPreferences(MUTATIO2, Context.MODE_PRIVATE);
  
      button = (ImageButton) findViewById(R.id.imageButton1);
      button.setImageResource(optio.getInt(MUTATIO, R.drawable.default)); 
  
      button.setOnLongClickListener(new OnLongClickListener(){
  
          @Override
          public boolean onLongClick(View v) {
  
  
  
  
  final Dialog dialog = new Dialog(MainActivity.this);
              dialog.setContentView(R.layout.dialog);
              dialog.setTitle("Titolo menù scelta");
  
  
  
              TextView text = (TextView) dialog.findViewById(R.id.text);
              text.setText("Scegli l'icona");
              ImageView image = (ImageView) dialog.findViewById(R.id.image);
              image.setImageResource(R.drawable.ic_launcher);
  
              dialog.show();
  
              Button dialogButtonLuce = (Button) dialog.findViewById(R.id.dialogButtonLuceID);
  
              dialogButtonLuce.setOnClickListener(new OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
  
                      button.setImageResource(R.drawable.lux);
                      signum = 1 ;
      SharedPreferences.Editor salvum = optio.edit();
      salvum.putInt("semper", R.drawable.lux);
  
           //Now I would save the flag-int-variable
  
      salvum.putInt("semper", 1);
      salvum.commit();
                      dialog.dismiss();
  
                  }
              });
  
  
    Button dialogButtonGas = (Button) dialog.findViewById(R.id.dialogButtonGasID);
  
      dialogButtonGas.setOnClickListener(new OnClickListener(){
  
              @Override
              public void onClick(View v) {
  
                  button.setImageResource(R.drawable.gas);
                  signum = 2;
                  SharedPreferences.Editor salvum = optio.edit();
                  salvum.putInt("semper", R.drawable.gas);
                  salvum.commit();
  
  
  
                  salvum.putInt("semper", 2);
                  salvum.commit();
   dialog.dismiss();}});
  
   Button RESET = (Button) dialog.findViewById(R.id.dialogRipristinaID);
   RESET.setOnClickListener(new OnClickListener(){
  
  @Override
  public void onClick(View v) {
      optio.edit().clear().commit();
  
      dialog.dismiss();
      }});return true;}});}
  
  private void operation() {
      button.setOnClickListener(new OnClickListener(){
  
          @Override
          public void onClick(View v) {
  
              if (signum==1) {
                  Toast.makeText(MainActivity.this, "I have a LUX", Toast.LENGTH_LONG)
                  .show();
                  }
              if (signum==2) {
                  Toast.makeText(MainActivity.this, "I have GAS GAS", Toast.LENGTH_LONG)
                  .show();
              }
              else  {
                  Toast.makeText(MainActivity.this, "VACUUM", Toast.LENGTH_LONG)
                  .show();
              }}});}}
  </code></pre>