title: Cannot get SharedPreferences value from one activity to another in Android
body: <p>I am using shared preferences for saving data and accessing it from another activity. I have used suggested methods but they don't seem to work.</p>
  
  <p>Code:</p>
  
  <pre><code>private static String Module_Pref="ModulePreference";
  </code></pre>
  
  <p>Activity A:</p>
  
  <pre><code> SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
          SharedPreferences.Editor editor = prefs.edit();
          editor.putString(key, value);
          editor.commit();
  </code></pre>
  
  <p><strong>Activity B:</strong></p>
  
  <pre><code>sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
          tempValue= sharedPreferences.getString(Module_Pref, "empty");
  </code></pre>
  
  <p><strong>Activity C:</strong></p>
  
  <pre><code> SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
          SharedPreferences.Editor editor = prefs.edit();
          editor.putString(key, value);
          editor.commit();
  </code></pre>
  
  <p>Here if we run first time then pass through  A, set <strong>nosave</strong>, then if we go to activity C then <strong>save</strong> the data.</p>
  
  <p>What is wrong with this code.I am getting a null. I looked at file explorer also where pref file isn't saved.</p>