title: Get Variable from another Activity (Android Studio)
body: <p>I know that there are a lot of answers to this question already, but I'm still having trouble dealing with this concept. </p>
  
  <p>An answer found <a href="https://stackoverflow.com/questions/12288629/how-do-i-get-a-variable-in-another-activity">here</a> shows: </p>
  
  <blockquote>
    <p>If you didn't want to use a global variable you could always create a method in your activity to return your string.</p>
  </blockquote>
  
  <pre><code>    public String getMyString(){
           return item; } 
  </code></pre>
  
  <blockquote>
    <p>Then in your current activity you could call:</p>
  </blockquote>
  
  <pre><code>    String myValue = LoginScreen.getMyString();
  </code></pre>
  
  <p>When I try this method, I am returned an error saying "Non-Static method can not be referenced from a static context". However if I make the <em>method</em> static it says that my <em>variable</em> needs to be static, but I need to <strong>update the variable</strong>. I'll include my code below.</p>
  
  <hr>
  
  <p>First Activity -</p>
  
  <pre><code>btnSEARCH.setOnClickListener(new View.OnClickListener() {
      public void onClick(View view) {
          if (editTextSearch.getText().toString() != null) {
              SearchQueryTerm = editTextSearch.getText().toString();
              editTextSearch.setText("");
          }
      }
  });
  
  public String getMyString(){
      return SearchQueryTerm;
  }
  </code></pre>
  
  <p>Second Activity-</p>
  
  <pre><code>String SearchQueryTerm = MainActivity.getMyString();
  </code></pre>
  
  <hr>
  
  <p>I truly appreciate any help you can give me in this. Thanks so much!! &lt;3</p>
  
  <hr>
  
  <p>This is my updated code - however it still crashes :(</p>
  
  <p>Activity 1</p>
  
  <pre><code>public void sendMessageIntent(View view) {
      Intent search_intent = new Intent(this, SearchActivity.class);
      api_intent.putExtra("my_variable", SearchQueryTerm);
      startActivity(search_intent);
  }
  </code></pre>
  
  <p>xml file</p>
  
  <pre><code> &lt;Button
          android:id="@+id/button_view"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="right"
          android:text="View"
          android:onClick="sendMessageIntent"
          /&gt;
  </code></pre>
  
  <p>Activity 2 - </p>
  
  <pre><code>public String SearchQueryTerm
  
  protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_enter_variable);
  
          if (extras != null) {
              SearchQueryTerm = extras.getString("my_variable");
          }
  }
  </code></pre>