title: Android - How do I get sharedpreferences from another activity?
body: <p>In my app there is a button (activity1). When user clicks it, I want no sound in the game. I thought I should do this by using sharedpreferences in activity1 in the onClick method of the button:</p>
  <pre><code>SharedPreferences.Editor editor = mPrefs.edit();
  editor.putString(&quot;sound&quot;,&quot;1&quot;);
  editor.commit();
  </code></pre>
  <p>The sound and the game starts in another activity (activity2). I need to read the set sharedpreferences there, but I don't know how to do it.</p>
  <p>Thanks</p>
  <p>Edit</p>
  <p>I have left this line out:</p>
  <pre><code>SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Activity1.this);
  </code></pre>
  <p>Based on your help in the Activity2.class I read the preferences like this:</p>
  <pre><code>SharedPreferences myPrefs = getSharedPreferences(&quot;Activity1&quot;, MODE_PRIVATE);  //Activity1.class
  String ifsound = myPrefs.getString(&quot;sound&quot;,&quot;&quot;);
                      
   if (ifsound.equals(&quot;1&quot;))
   {
       Toast.makeText(Activity1.this, &quot;1&quot;, Toast.LENGTH_LONG).show();
   }
   else
   {
        Toast.makeText(Activity1.this, &quot;0&quot;, Toast.LENGTH_LONG).show();
   }
  </code></pre>
  <ol>
  <li>In Activity1.class i click on the button to set the &quot;sound&quot; to &quot;1&quot;.</li>
  <li>I click on another btn that opens Activity2.class where I always get always &quot;0&quot; in the Toast msg.</li>
  </ol>