title: Android: Retrieve int saved in PreferenceManager getDefaultSharedPreferences in another activity
body: <p>I am trying to save data using default <code>Shared Preferences</code>, but cannot get this code working.</p>
  
  <p>I cant retrieve an <code>int</code> value in another activity.</p>
  
  <p>In my first activity, in <code>onCreate</code>, I want to create a <code>scorecounter</code> that counts up every time you receive points. It will be initiated on first run.</p>
  
  <pre><code>SharedPreferences preferences =  PreferenceManager.getDefaultSharedPreferences(this);
  SharedPreferences.Editor editor = preferences.edit();
  
  if (preferences.getBoolean("first_run", true)) 
  {   
  editor.putInt("totalpoang", 0);
  editor.commit();
      preferences.edit().putBoolean("first_time", false);
  }
  </code></pre>
  
  <p>In my <code>Activity B</code> I want to retrieve the value, modify it, and then save it in preferences again.</p>
  
  <pre><code>SharedPreferences preferences =  PreferenceManager.getDefaultSharedPreferences(this);
  SharedPreferences.Editor editor = preferences.edit();
  int poang = preferences.getInt(totalpoang, 0);
  editor.putInt("antalpoang", totalpoang);
  editor.commit();
  </code></pre>
  
  <p>However <strong>I only get the error totalpoang cannot be resolved as a variable</strong>. </p>
  
  <p>I initialized it as a <code>int</code> in the first Activity, and I am trying to retrieve it as an <code>int</code>.</p>
  
  <p>What am I doing wrong?</p>