title: How to transfer data from one activity to another in android
body: <p>It might sound simple but I can't make it working.  I have two activities. Which first one is a form, and second one is showing data from a JSON file based on values entered in the first activity.</p>
  
  <p>So I am trying to make a simple version of it. I have a EditText, and a button, so when they press the button, whatever was in the EditText will be in the TextView of the next activity.</p>
  
  <p>Here is my code so far:
  <strong>Main Activity</strong></p>
  
  <pre><code>static TextView textView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      textView = (TextView) findViewById(R.id.editText1);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  public void transferIT(View view){
      Intent intent = new Intent(this, Page.class);
      startActivity(intent);
  }
  
  public static String getText(){
      String data = (String) textView.getText();
      return data;
  }
  </code></pre>
  
  <p><strong>Main XML</strong></p>
  
  <pre><code>&lt;EditText
      android:id="@+id/editText1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignTop="@+id/textView1"
      android:layout_centerHorizontal="true"
      android:ems="10"
      android:hint="Enter Text to transfer" /&gt;
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerVertical="true"
      android:text="Transfer it"
      android:onClick="transferIT" /&gt;
  </code></pre>
  
  <p><strong>Second Activity</strong></p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_page);
      // Show the Up button in the action bar.
      setupActionBar();
  
  
      TextView enteredValue = (TextView)findViewById(R.id.text);
  
      enteredValue.setText(MainActivity.getText());
  
  }
  </code></pre>
  
  <p><strong>Second XML</strong></p>
  
  <pre><code>&lt;TextView
      android:id="@+id/text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="58dp" /&gt;
  </code></pre>
  
  <p>In this way I made a method for the data of the EditText and in the other activity I call it to get access to it. Currently when I press the button it stops working. So what is your solution for having the data of the form in other activity ?</p>