title: How to use SharedPreferences to save the text entered in edittext and display it in TextView in another Activity
body: <p>I am trying to save the text entered in edittext from an activity and send it to another activity so that it can be displayed in a textview which is invisible at first. So pls help me..</p>
  
  <p>This is my first xml.
  main.xml</p>
  
  <pre><code>        &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" &gt;
  
          &lt;EditText
          android:id="@+id/editText5"
          android:layout_width="70dp"
          android:layout_height="wrap_content"
          android:layout_marginTop="12dp"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:inputType="number" /&gt;
  
          &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/textView3"
          android:layout_alignParentBottom="true"
          android:layout_marginLeft="49dp"
          android:text="@string/save" /&gt;
  
       &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This is my second xml.</p>
  
  <p>next.xml:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;          
  
      &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/imageView1"
      android:layout_toRightOf="@+id/imageView1"
      android:text="Medium Text"
      android:visibility="invisible"
      android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
     &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This is my main actvity code.
     MainActivity.java</p>
  
  <pre><code>   public class MainActivity extends Activity {
  
      public SharedPreferences savedData;
      private Button mbtn_save;
      private EditText medit_currency;
      public String s1;
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
              mbtn_save=(Button)findViewById(R.id.button1);
              medit_currency=(EditText)findViewById(R.id.editText5);
              savedData=PreferenceManager.getDefaultSharedPreferences(this);
  
         mbtn_save.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
              s1=medit_currency.getText().toString();
              savePreference(s1,s1);
              Intent i=new Intent(MainActivity.this,Next.class);
              startActivity(i);
          }
      });
         public void savePreference(String key,String value)
  {
      savedData=getPreferences(MODE_PRIVATE);
      SharedPreferences.Editor e=savedData.edit();
      e.putString(key, value);
      e.commit();
      Toast.makeText(MainActivity.this, "Saved", Toast.LENGTH_SHORT).show();
  
  }
        public void showPreference(String key)
  {
      savedData=getPreferences(MODE_PRIVATE);
      String text=savedData.getString(key, "");
  }
  }}
  </code></pre>
  
  <p>This is my second activity</p>
  
  <p>Next.java</p>
  
  <pre><code>public class Next extends Activity {
  MainActivity ma;
  private TextView mtext_one;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.next);
      mtext_one=(TextView)findViewById(R.id.textView1);
      ma=new MainActivity();
      ma.savedData=getPreferences(MODE_PRIVATE);
      mtext_one.setVisibility(CONTEXT_INCLUDE_CODE);
      mtext_one.setText(ma.savedData.getString("10", ""));
  }
  
  
  
  }
  </code></pre>
  
  <p>I cant get the text displayed in Next.java once i save the preference and move to another activity.. help me..</p>