title: How to access a string value of a shared preference from a method of another class
body: <p>The title is the question. I have saved a string value in the shared preference and i was able to access it in that class. Now i want to access it from a another method of another class. Tried some ways but didn't work.  </p>
  
  <p>The class that saves string inside shared preference:</p>
  
  <p><a href="http://pastie.org/4254511" rel="nofollow">http://pastie.org/4254511</a></p>
  
  <p>Class trying to retrieve the username that was previously save in shared preference:</p>
  
  <pre><code>public class testSharedPrefernce extends Activity{
  TextView tv;
   @Override
      protected void onCreate(Bundle savedInstanceState){
       super.onCreate(savedInstanceState);
       setContentView(R.layout.lo);
       tv = (TextView)findViewById(R.id.textView1);
       SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
       String name = myPrefs.getString("NAME", "YourName");
       tv.setText(name);
   }
  </code></pre>
  
  <p>}</p>